如何使用此prepare语句从数据库中获取数据

Hai*_*Ali 4 php mysql pdo

//this is my connection function. It is connecting databse successfully when I check.
$conn = connection($config['servername'],$config['username'],$config['password']);
Run Code Online (Sandbox Code Playgroud)

在此之后,我使用以下代码从数据库中获取数据

$id = 2;
if($conn) {

    try {

        $stmt = $conn->prepare('SELECT * FROM customer_tbl WHERE cus_id = :id');
        $stmt->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        $stmt->bindParam(':id', $id);

        $results = $stmt->execute();

    }catch (PDOException $e){

        echo 'Error: ' . $e->getMessage();
    }

}
Run Code Online (Sandbox Code Playgroud)

此代码在浏览器上显示以下错误消息

错误:SQLSTATE [IM001]:驱动程序不支持此功能:此驱动程序不支持设置属性

我的代码出了什么问题?为什么我无法从数据库中获取数据?

如果我想使用prepare语句从databese获取此指定数据如何编码?

gur*_*uri 7

添加以下内容

$stmt->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Run Code Online (Sandbox Code Playgroud)

在与$connObject 的连接字符串之后

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Run Code Online (Sandbox Code Playgroud)

要获取数据使用

$stmt->execute();    
$rows= $stmt->fetch(PDO::FETCH_ASSOC);
print_r($rows); // to print an array
Run Code Online (Sandbox Code Playgroud)

它将以关联数组格式返回数据.PDO提供了各种提取选项看这里