note 92771 deleted from function.sqlite-fetch-single by cmb
| From: | cmb@php.net | Date: | Mon, 02 Nov 2020 14:59:53 +0000 |
| Subject: | note 92771 deleted from function.sqlite-fetch-single by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215734@lists.php.net to get a copy of this message | ||
Note Submitter: visavi dot net at mail dot ru (Vantuz)
----
With the help of sqlite_fetch_single, you can quickly and easily calculate the number of elements in
the table
<?php
// create new database (OO interface)
$db = new SQLiteDatabase('database.db', 0666);
// create table inbox and paste data
$db->queryExec("
CREATE TABLE inbox (
inbox_id INTEGER NOT NULL PRIMARY KEY,
inbox_send varchar(20) NOT NULL,
inbox_text TEXT NOT NULL,
inbox_time INTEGER UNSIGNED NOT NULL,
inbox_user varchar(20) NOT NULL
);");
$ins_query = "
INSERT INTO inbox (inbox_send, inbox_text, inbox_time, inbox_user) VALUES ('Ilia1',
'Message1', '".time()."', 'my_name');
INSERT INTO inbox (inbox_send, inbox_text, inbox_time, inbox_user) VALUES ('Ilia2',
'Message2', '".time()."', 'user');
INSERT INTO inbox (inbox_send, inbox_text, inbox_time, inbox_user) VALUES ('Ilia2',
'Message3', '".time()."', 'my_name');
";
$db->queryExec($ins_query);
//view all posts by my_name
$total = $db->singleQuery("SELECT count(*) FROM inbox WHERE
inbox_user='my_name';");
echo $total;
// the result will be the number 2
/* P.S. sorry for my english */
?>