public static function findById($fields='',$tagName,$priId){
$sql='select %s from %s where id=%d';
return self::getRow(sprintf($sql,self::parseField($fields),$tabName,$priId));
}
//分析查找域
public static function parseField($fields){
if(is_array($fields)){
array_walk($fields, array('PdoMysql','addSpecilChar'));
$fieldsStr=implode(',',$fields);
}elseif(is_string($fields)&&!empty($fields)){
if(strpos($fields,'`')===false){
$fields=explode(',',$fields);
array_walk($fields,array('PdoMysql','addSpecilChar'));
$fieldsStr=implode(',',$fields);
}else{
$fieldsStr=$fields;
}
}else{
$fieldsStr='*';
}
return $fieldsStr;
}
public static function addSpecilChar($value){
if($value==='*'||strpos($value,'.')!==false||strpos($value,'`')!==false){
//不用处理
}elseif(strpos($value,'`')===false){
$value='`'.trim($value).'`';
}
return $value;
}
$tabName='user1';
$priId='20';
$fields='username,email';
print_r($PdoMysql->findById($fields,$tabName,$priId));
为什么显示You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id=20' at line 1?