note 90712 added to intro.sqlite3
| From: | dzcowart at gmail dot com | Date: | Tue, 05 May 2009 18:00:21 +0000 |
| Subject: | note 90712 added to intro.sqlite3 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-154257@lists.php.net to get a copy of this message | ||
In Ubuntu the package php5-sqlite3 uses this method for accessing sqlite3 databases:
(from /usr/share/doc/php5-sqlite3/examples/example1.php)
/*
* create a SQLite3 handle.
*
* Note: in-memory database are created by the magic keyword ":memory:"
*
*/
$db = sqlite3_open(":memory:");
if (!$db) die ("Could not create in-memory database..");
/*
* create a simple test and insert some values..
*/
$ret = sqlite3_exec ($db, "CREATE TABLE test (id INTEGER, name TEXT, age INTEGER);");
if (!$ret) die (sqlite3_error($db));
sqlite3_exec($db, "INSERT INTO test (id,name,age) VALUES (1,'michael',32)");
sqlite3_exec($db, "INSERT INTO test (id,name,age) VALUES (2,'bob',27)");
sqlite3_exec($db, "INSERT INTO test (id,name,age) VALUES (3,'martin',12)");
/*
* Create a query
*/
$query = sqlite3_query($db, "SELECT * FROM test ORDER BY age DESC");
if (!$query) die (sqlite3_error($db));
/*
* sqlite3_fetch_array() returns an associative array
* for each row in the result set. Key indexes are
* the columns names.
*/
while ( ($row = sqlite3_fetch_array($query)))
{
printf("%-20s %u\n", $row['name'], $row['age']);
}
/*
* do not forget to release all handles !
*/
sqlite3_query_close($query);
sqlite3_close ($db);
?>
----
Server IP: 209.41.74.194
Probable Submitter: 139.62.60.21
----
Manual Page -- http://www.php.net/manual/en/intro.sqlite3.php
Edit -- https://master.php.net/note/edit/90712
Del: integrated -- https://master.php.net/note/delete/90712/integrated
Del: useless -- https://master.php.net/note/delete/90712/useless
Del: bad code -- https://master.php.net/note/delete/90712/bad+code
Del: spam -- https://master.php.net/note/delete/90712/spam
Del: non-english -- https://master.php.net/note/delete/90712/non-english
Del: in docs -- https://master.php.net/note/delete/90712/in+docs
Del: other reasons-- https://master.php.net/note/delete/90712
Reject -- https://master.php.net/note/reject/90712
Search -- https://master.php.net/manage/user-notes.php