首先,我使用 MySQL POO API,其中有重要的部分:
public function query($query,$params = null,$fetchmode = PDO::FETCH_ASSOC)
{
$query = trim($query);
$this->Init($query,$params);
if (stripos($query, 'select') === 0){
return $this->sQuery->fetchAll($fetchmode);
}
elseif (stripos($query, 'insert') === 0 || stripos($query, 'update') === 0 || stripos($query, 'delete') === 0) {
return $this->sQuery->rowCount();
}
else {
return NULL;
}
}
_
This API has a loging and showing Class to save and show the SQL error, there is my error :
SQLSTATE[42000]: Syntax error or access violation: 1064 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 firstname = ? AND age = ? ?' at line 1
Raw SQL : SELECT * FROM users WHERE id = :iduser
在此之后我找到了包含的 SQL,有函数和使用这个函数的代码:
function get_member_informations($id)
{
global $bdd;
$dn = $bdd->query("SELECT * FROM users WHERE id = :iduser", array("iduser" => $id));
$dn[0]['avatar'] = base64_decode($dn[0]['avatar']);
return $dn;
}
以及使用此功能的代码:
$profil = $bdd->query("SELECT * FROM users WHERE username = :username", array("username"=>$username));
$id = $profil[0]['id'];
$profile = get_member_informations($id);
我知道这是一个 mysql 和 php 问题,所以要检查它是否不是 $id 导致错误的原因,我在上面做了一个 print_r,但一切正常。我不知道如何解决这个问题,任何帮助将不胜感激