【问题标题】:PDO error in the "WHERE" [closed]“WHERE”中的 PDO 错误 [关闭]
【发布时间】:2012-08-01 23:35:58
【问题描述】:

这段代码有什么问题,它告诉我这个,但我看不出有什么问题:

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 B='achillea_millefolium_credo'' at line 1

这是我的代码:

(之前)获取信息: 如果我们回显“$all_db_types_associations['nom_url']” 它会回显“B”(我数据库中的 B 列)

如果我们回显“$plante” 它会呼应“achillea_millefolium_credo”(植物的名称)

$plante_undecoded = htmlspecialchars($_GET["plante"]);
$plante = htmlspecialchars_decode(htmlspecialchars_decode($plante_undecoded));

try
{
    $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
    $bdd = new PDO('mysql:host=' .$host .';dbname=plantes', $username, $password, $pdo_options);

    $bdd->query("SET NAMES 'utf8'");

    $pdo = 'SELECT * FROM ' .$current_db_name ." ORDER BY " .$all_db_types_associations['nom_bot'] ." WHERE " .$all_db_types_associations['nom_url'] ."=? ";
    //echo $pdo ." <br />";

    $reponse = $bdd->prepare($pdo);
    $reponse->execute(array($plante));



    while ($donnees = $reponse->fetch())
    {
        //things here...
    }

    $reponse->closeCursor();
}

catch(Exception $e)
{
    die('Erreur : '.$e->getMessage());
}

是因为我在 MySQL 中的列名是大写字母(“B”)吗?否则……什么大?

【问题讨论】:

  • ORDER BY 必须在WHERE 之后

标签: mysql pdo where mysql-error-1064


【解决方案1】:

您的ORDER BY 子句需要在您的WHERE 子句之后。

SELECT col FROM table WHERE condition ORDER BY col

【讨论】:

  • 非常感谢老兄...原来如此简单!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多