note 128631 added to class.sqlite3result
| From: | vitas dot lowang at seznam dot cz | Date: | Sun, 25 Jun 2023 18:41:49 +0000 |
| Subject: | note 128631 added to class.sqlite3result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220591@lists.php.net to get a copy of this message | ||
I was thinking how to add a function to count rows of last query into MyDB class and with help from
ChatGPT I got it working :)
class MyDB extends SQLite3 {
private $lastQueryResult;
function __construct() {
$this->open('l:\database\database.db');
}
function query($query) {
$this->lastQueryResult = parent::query($query);
return $this->lastQueryResult;
}
function numRows() {
if ($this->lastQueryResult !== false) {
$count = 0;
while ($this->lastQueryResult->fetchArray()) {
$count++;
}
return $count;
}
return 0;
}
}
$db=new MyDB();
$res=$db->query($somequery);
$numrows=$dbdat->numRows(); //count rows of the last query
echo "numrows: $numrows\n<br>";
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 85.160.41.177)
----
Manual Page -- https://php.net/manual/en/class.sqlite3result.php
Edit -- https://main.php.net/note/edit/128631
Del: integrated -- https://main.php.net/note/delete/128631/integrated
Del: useless -- https://main.php.net/note/delete/128631/useless
Del: bad code -- https://main.php.net/note/delete/128631/bad+code
Del: spam -- https://main.php.net/note/delete/128631/spam
Del: non-english -- https://main.php.net/note/delete/128631/non-english
Del: in docs -- https://main.php.net/note/delete/128631/in+docs
Del: other reasons-- https://main.php.net/note/delete/128631
Reject -- https://main.php.net/note/reject/128631
Search -- https://main.php.net/manage/user-notes.php