问题描述
我正在尝试对数据库运行查询,但是PDO不会产生任何结果。
这有效。
$coon = new PDO("mysql:host=localhost;port=3308;dbname=developer","root","");
$fetch = $coon->query("SELECT * FROM users");
var_dump($fetch->fetch());
以上代码始终返回true
public static function query($statement,$data = null)
{
$connection = self::get_connection();
if(!$data)
return $connection->query($statement);
$stmt = $connection->prepare($statement);
return $stmt->execute($data);
}
这种方式总是返回true
而不是PDO查询对象。
我已经尝试使用try / catch块来查看是否有任何错误..但没有任何错误。
我不知道那是什么,因为显然一切都正确。
解决方法
execute
返回true
或false
。
您的PDOStatement object
(结果对象,PDO查询对象)是$stmt
。