2013-07-29 158 views
1

我试图从我的MySQL数据库,通常正常工作正常。但今天我得到这个错误Fatal error: Call to a member function setFetchMode() on a non-object in "Way too long path to file here"奇怪的MySQL/PHP错误

这是我的PHP代码:

$conn = new PDO('mysql:host=localhost;port=3306;name=erty', 'erty', 'Ops, that my password ...'); 

$result = $conn->query("SELECT name FROM mod_devs"); 
$result->setFetchMode(); 
foreach ($result as $row) { 
    echo '<tr><td>'.$row['name'].'</td></tr>'; 
} 

现在,你大概明白了我的目标:)

+1

发现错误,在连接我写的名字= erty不DBNAME = erty!对不起,占用了你的时间:( –

回答

0

我刚发现错误。在连接我写name=erty而不是dbname=erty

抱歉占用您的时间:(

1

一般Call to a member function setFetchMode() on a non-object意味着$结果不可用。可能是因为MySQL错误 - 无论是连接还是查询。检查if($conn)if($result)

+0

$康恩返回true,但$结果恢复假这是奇怪的,因为相同的查询在PMA –

+0

中正常工作,使用'print_r($ conn-> errorInfo())'查看确切的错误。 –

1

你仍然需要因此,而不是获取结果... 的foreach ....做一段时间...

while ($row = $result->fetch()) { 
    //your code here 

    } 
0

也许你需要准备不查询

 $result = $conn->prepare("SELECT name FROM mod_devs"); 

或本

$result->setFetchMode(PDO::FETCH_OBJ);