【发布时间】:2016-04-08 07:06:16
【问题描述】:
我构建了restful API及其工作,但是当我尝试将参数传递给链接时,下面显示错误,尽管当我打印参数时结果是正确的!
详情
类型:PDOException
代码:42000
消息:SQLSTATE[42000]:语法错误或访问冲突:1064 You 您的 SQL 语法有错误;检查对应的手册 您的 MySQL 服务器版本,以便在 'where 附近使用正确的语法
Journal_namelike 'Abhinav%' AND is_reported=1' 在第 1 行文件:...路径/index.php
行:15
第 15 行是“$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();
?>
【问题讨论】: