我错了吗? FETCH_ASSOC

时间:2017-06-15 04:52:58

标签: php

我错了吗?我正在使用FETCH_ASSOC
它不起作用,有人能帮帮我吗?我不知道它有什么问题 这是我的代码

 if(!empty($_POST)){
        if (isset($_POST['id']) && $_POST['id'] > 0){
            $id=$_POST['id'];
            GetSuppliersView();
        }
    }
    function GetSuppliersView() {
        global $db;
        global $id;
        try{
            $query = $db->query("
   SELECT
        suppliers.*,
        third_party_services.name as servicename
    FROM
        suppliers
    INNER JOIN
        suppliers_services
    ON
        suppliers.id = suppliers_services.supplier_id
    LEFT JOIN
        third_party_services
    ON
        suppliers_services.id = third_party_services.id
    WHERE
        suppliers_services.supplier_id = $id
            ");
            $row=$query->fetch(PDO::FETCH_ASSOC); 
            $result['success'] = true;
            $result['result'] = $row;
            echo json_encode($result);
        return true;
        } catch (PDOException $pe) {
            return false;
        }
    }
你可以帮我吗?

1 个答案:

答案 0 :(得分:-1)

请试试这个

$query->setFetchMode(PDO::FETCH_CLASS, 'Person');
$row = $query->fetch();

而不是

$row=$query->fetch(PDO::FETCH_ASSOC);