简体   繁体   中英

php sqlite3 - get result from prepared statement

All the examples and documentation didnt really help or even offer an example for this so I m gonna ask here:

$db = new SQLite3(database.db);
$stmt = $db->prepare('SELECT COUNT(uid)  FROM kunden WHERE date = :date');
$stmt->bindValue(':ldate',$today,SQLITE3_TEXT);
$result =  $stmt->execute;

How can I get the result from that prepared statement? I know execute is not supposed to return a result. I tried using query and query_single but that didnt work. var_dump($result->fetchArray()); also didnt work. Help is much appreciated.

SQLite3Stmt::execute() is a function, and needs to be called as such:

$db = new SQLite3('database.db');
$stmt = $db->prepare('SELECT COUNT(uid)  FROM kunden WHERE date = :date');
$stmt->bindValue(':ldate',$today,SQLITE3_TEXT);
$result =  $stmt->execute();

You can then fetch the result like this:

$array = $result->fetchArray();
echo $array['COUNT(uid)'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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