SQL查询适用于PHPMYADMIN但不适用于邮递员

时间:2018-06-14 17:18:47

标签: php mysql sql json rest

我有一个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,但我不确定,真的不知道如何解决这个问题

0 个答案:

没有答案