downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Instalação/Configuração> <SQLite3
[edit] Last updated: Tue, 18 Jun 2013

view this page in

Introdução

Support for SQLite version 3 databases.



add a note add a note User Contributed Notes Introdução - [2 notes]
up
0
dzcowart at gmail dot com
4 years ago
In Ubuntu the package php5-sqlite3 uses this method for accessing sqlite3 databases:
(from /usr/share/doc/php5-sqlite3/examples/example1.php)

<?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);
?>
up
-2
Variofox
8 months ago
Ubuntu 12.04 and up no longer has php5-sqlite3 included.

So this will no loger work:
<?php
$db
= sqlite3_open(":memory:");
?>

Use this:
<?php
$db
= new SQLite3('mysqlitedb.db');

$results = $db->query('SELECT bar FROM foo');
while (
$row = $results->fetchArray()) {
   
var_dump($row);
}
?>

 
show source | credits | sitemap | contact | advertising | mirror sites