Php 对非对象调用成员函数fetchAll()-
所以,在这个网站上有很多这样的例子 但是它们中的大多数都混合了一些其他的东西,比如类、大量的参数等等 我有一些非常基本的代码,不,真的,可能是最基本的:Php 对非对象调用成员函数fetchAll()-,php,mysql,pdo,Php,Mysql,Pdo,所以,在这个网站上有很多这样的例子 但是它们中的大多数都混合了一些其他的东西,比如类、大量的参数等等 我有一些非常基本的代码,不,真的,可能是最基本的: try { $connection = new PDO("mysql:host=localhost;dbname=desertstormweb_mybb", $mysql_user, $mysql_pass); $test = 'SELECT * from mybb_users'; $statement = $con
try {
$connection = new PDO("mysql:host=localhost;dbname=desertstormweb_mybb", $mysql_user, $mysql_pass);
$test = 'SELECT * from mybb_users';
$statement = $connection->prepare($test);
$statement = $statement->execute();
$result = $statement->fetchAll();
print($result);
} catch(PDOException $e) {
echo $e->getMessage();
}
基本上,我只是尝试返回表中的行,现在我已经使用PDO很多次了,我从来没有遇到过这个问题
我甚至开始引用我在过去做过的其他脚本,但我不太明白
发生什么事了 不要指定执行,否则会覆盖对象:
$test = 'SELECT * from mybb_users';
$statement = $connection->prepare($test);
$statement->execute(); // invoke the execute, but don't overwrite
$result = $statement->fetchAll(); // PDO::FETCH_ASSOC
PDOStatement::execute在成功时返回TRUE,在失败时返回FALSE。
因此,我们没有:
$statement = $statement->execute();
只用
$statement->execute();
或
Brb,用我的头骨在我的墙上又打了一个洞。我花了两个小时摆弄这个基本代码,就这么简单。谢谢,我会在几分钟内标记为正确。@Christian.tucker-hehe:D是的,那些微妙的事情有时会破坏事情。当然没问题,很高兴能帮上忙是的!现在我必须弄清楚为什么它返回一个空数组。。。今天可不是我的日子,查询在phpmyadmin上完美执行,....@Christian.tucker将其放在
$connection=new PDO(…)
下面<代码>$connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常)代码>并始终打开错误报告
$statement->execute();
if ($statement->execute())
{
$result = $statement->fetchAll();
print($result);
}