reptc3
reptc3

Reputation: 13

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.

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

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.

I already tried to use a try/catch block to see if there any errors.. but nothing.

I don't know what it can be, because apparently everything is correct.

Upvotes: 0

Views: 52

Answers (1)

user3783243
user3783243

Reputation: 5224

execute returns true or false.

Your PDOStatement object (result object, PDO query object ) is $stmt.

Upvotes: 1

Related Questions