0

首先,我使用 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,但一切正常。我不知道如何解决这个问题,任何帮助将不胜感激

4

1 回答 1

0

我是第二个开发它的开发者。检查后,该类报告了错误的原始 SQL,我已修复该问题,检查后,它是:

FROM :table
"table"=> $this->table

更正一下,谢谢大家,不便之处见谅。@dleiftah ==> 感谢您的出色回答;)

于 2013-11-06T16:23:22.157 回答