-1

I've been getting this error,

"Fatal error: Call to a member function setFetchMode() on a non-object in C:\Users\Public\wamp\www\audiotextCSVUpload\modified.php on line 34".

Can you please help me what is causing the error. In one of my computer, it is ok, but in our office, the error exists. Find below the code:

<?php
require_once 'dbconfig.php';

try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

    $sql = 'SELECT phone, last_name, first_names
            FROM contacts';

    $q = $conn->query($sql);
    $q->setFetchMode(PDO::FETCH_ASSOC);

} catch (PDOException $pe) {
    die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
4

2 回答 2

1

检查错误

$q = $conn->query($sql);
if (!$q) {
    echo "\nPDO::errorInfo():\n";
    print_r($conn->errorInfo());
}
于 2013-10-18T05:50:33.903 回答
0

似乎问题在于您的查询,表联系人不存在或您检索的字段不正确。

向 PDO 添加异常是个好主意,在后面添加$conn

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

并检查错误

于 2013-10-18T06:24:07.087 回答