en Home Creating models for the Zend Framework from command line via phpcli Messenger Laravel Framework Load functions and array's Zend ACL Autoload Multiple PHP installations e() for echo fixing php's gettype function Read Folder PHP goto statement

num_row with PDO

There is no num_row() function for PHP PDO

Here are my two solutions:

One with prepare & execute:

    db->prepare($sql);
    $sth->execute(array($key));
    $rows = $sth->fetch(PDO::FETCH_NUM);
    echo $rows[0];

One with query:

    db->query($sql);
    $row = $result->fetch(PDO::FETCH_NUM);
    echo $row[0];

Tags: code pdo php sql


First Created: 2011-06-10T06:33:51Z
Last Modified: 2026-04-05 19:35