简体   繁体   English

PDO 查询不返回 object

[英]PDO query does not return the object

I'm trying to run a query against the database, but the PDO does not result in anything.我正在尝试对数据库运行查询,但 PDO 不会产生任何结果。

this works.这行得通。

$coon = new PDO("mysql:host=localhost;port=3308;dbname=developer", "root", "");
$fetch = $coon->query("SELECT * FROM users");
var_dump($fetch->fetch());

the above code always return true上面的代码总是返回 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);
}

this way always return true and not a PDO query object.这种方式总是返回true而不是 PDO 查询 object。

I already tried to use a try/catch block to see if there any errors.. but nothing.我已经尝试使用 try/catch 块来查看是否有任何错误.. 但什么也没有。

I don't know what it can be, because apparently everything is correct.我不知道它可能是什么,因为显然一切都是正确的。

execute returns true or false .execute返回truefalse

Your PDOStatement object (result object, PDO query object ) is $stmt .您的PDOStatement object (结果 object,PDO 查询是 $$$$$ $stmt )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM