mysql原生態操作関数

3409 ワード

//conf.php  
return array(
    'host'=>'localhost',
    'user'=>'root',
    'pwd'=>'910420',
    'db'=>'boke',
    'charset'=>'utf8',
    'salt'=>'Lsd":Adfqef]',
);

//mysql.php  
".$sql);
    }else{  
        mLog('  !'."
".$sql.'
'.mysql_error()); } return $rs; } /** * * log *@param string $sql * , log */ function mLog($log){ $filename=ROOT.'/log/'.date('Ymd').'.txt'; $data='----------------------------'."
"; $data.= date('Y/m/d H:i:s')."
"; $data.= $log; $data.="
"."------------------------------"."
"; file_put_contents($filename,$data,FILE_APPEND); } /** * select , * *@param string $sql *@return array , false */ function getAll($sql){ $rs=mQuery($sql); if(!$rs){ return false; }else{ $arr=array(); while($row=mysql_fetch_assoc($rs)){ $arr[]=$row; } return $arr; } } /** * * *@param string $sql *$return array , false */ function find($sql){ $rs=mQuery($sql); if(!$rs){ return false; }else{ $row=mysql_fetch_assoc($rs); } return $row; } /** * * select *@param string $sql select *@return array string , false */ function getCount($sql){ $rs=mQuery($sql); return $rs? mysql_fetch_row($rs) : false; } /** * * update insert , *@param string $table *@param array $data , , *@param sting $act , , *@paran string $where update where, */ function inUp($table,$data,$act='insert',$where='0'){ if($act=='insert'){ $sql="insert into ".$table." ("; $sql.=implode(',',array_keys($data)).") values ('"; $sql.=implode("','",array_values($data))."')"; //return $sql; return mQuery($sql); }elseif($act=='update'){ $str=''; foreach($data as $k =?> $v){ $str.=$k."='".$v."',"; } $str=rtrim($str,','); $sql="update ".$table." set ".$str." where ".$where; return mQuery($sql); }else{ return false; } } /** * * insert id *@return int */ function lastId(){ return mysql_insert_id(con()); } //$sql="delete from cat where cat_id='11'"; //var_dump(inUp('cat',array('id'=>1,'name'=>'ddd'),'insert')); ?>