我构建了 restful API 及其工作,但是当我尝试将参数传递给链接时,下面显示错误,尽管当我打印参数时结果是正确的!
详细信息
Type: PDOException
Code: 42000
Message: 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
Journal_name
like 'Abhinav%' AND is_reported=1' at line 1File: ...path/index.php
Line: 15
and line 15 is "$stmt = $db->query($sql);"
index.php
<?php
// index.php
require 'confing.php';
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get('/rout', function() use ($app) {
$db =getDB();
$title = $app->request()->params('title');
// echo 'title ='. $tilte print the correct title name get it by link
$sql = "SELECT J_name FROM J where where `J_name` like '".$title."%' AND is_reported=1;";
$stmt = $db->query($sql);
$pre = $stmt->fetchAll(PDO::FETCH_OBJ);
$sql2 = "SELECT P_Name FROM P where `P_Name` like '".$title."%' AND is_reported=1;";
$stmt2 = $db->query($sql2);
$pre2 = $stmt2->fetchAll(PDO::FETCH_OBJ);
echo json_encode($pre);
echo json_encode($pre2);
});
$app->run();
?>
最佳答案
在错误的查询中使用两次 where condition
。
$sql = "SELECT J_name FROM J where where `J_name` like '".$title."%' AND is_reported=1";
^^^^^^^^^^^
删除一个where
应该是
$sql = "SELECT J_name FROM J where `J_name` like '".$title."%' AND is_reported=1";
关于php - 应用程序错误 "SQLSTATE[42000]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370226/