我有一个PHP REST API和这个函数:
function fillProfil($request) {
require_once 'db.php';
$emp = json_decode($request->getBody());
$id = $request->getAttribute("id");
try {
$sql = "select * FROM users WHERE id= :id";
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("id", $id);
$stmt->execute();
$wines = $stmt->fetch(PDO::FETCH_OBJ);
$db = null;
if($wines->type=="client"){
return json_encode($wines);
}else{
$sql = "select * FROM `users` JOIN (`professionnel` JOIN `metiers` ON professionnel.metierid=metiers.id) ON users.id=professionnel.userid WHERE users.id= :id ";
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("id", $id);
$stmt->execute();
$wines = $stmt->fetch(PDO::FETCH_OBJ);
$db = null;
return json_encode($wines);
}
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
问题是select * FROM users JOIN (professionnel JOIN metiers ON professionnel.metierid=metiers.id) ON users.id=professionnel.userid WHERE users.id= :id
当我在phpmyadmin上执行此查询时它可以正常工作,但是当我执行php上的函数时,我的管理员无法正常工作,我尝试json_last_error_msg()
并获得了{{1} }
我认为问题来自JSON,但我不确定,真的不知道如何解决这个问题