wiki/HowtoSQLite.md

71 lines
1.4 KiB
Markdown
Raw Normal View History

2018-05-21 23:16:43 +02:00
---
categories: databases
title: Howto SQLite
---
2016-12-29 11:25:39 +01:00
2018-05-21 23:16:43 +02:00
* Documentation : <http://www.sqlite.org/docs.html>
2016-12-29 11:25:39 +01:00
2018-05-21 23:16:43 +02:00
[SQLite](https://www.sqlite.org/) est base de données SQL stockée dans un simple fichier. Cela permet une utilisation simple (en ligne de commande, PHP, C, Ruby, etc.) et légère (il n'y a pas de démon). SQLite est utilisé dans des applications web légère et des logiciels connus comme Firefox.
2016-12-29 11:25:39 +01:00
2018-05-21 23:16:43 +02:00
## Installation
~~~
# apt install sqlite3
$ sqlite3 --version
3.16.2 2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209
2016-12-29 11:25:39 +01:00
~~~
2018-05-21 23:16:43 +02:00
## Utilisation
* Documentation CLI : <http://www.sqlite.org/cli.html>
Créer un fichier SQLite :
2016-12-29 11:25:39 +01:00
~~~
2018-05-21 23:16:43 +02:00
$ sqlite3 foo.db
SQLite version 3.16.2 2017-01-06 16:32:41
Enter ".help" for usage hints.
sqlite> sqlite> .tables
sqlite> .exit
$ file foo.db
foo.db: empty
~~~
Créer une table :
~~~
sqlite> create table foo (i int);
sqlite> .tables
foo
sqlite> .schema foo
CREATE TABLE foo (i int);
~~~
Actions sur une table :
~~~
sqlite> INSERT INTO foo VALUES (42);
sqlite> SELECT * FROM foo;
42
sqlite> UPDATE foo SET i=43 WHERE i=42;
sqlite> DELETE FROM foo WHERE i=43;
sqlite> DROP TABLE foo;
~~~
## PHP et SQLite
* <http://php.net/manual/fr/book.sqlite.php>
~~~
$db = sqlite_open('foo.db');
sqlite_query($db,'CREATE TABLE foo (i int)');
sqlite_query($db,"INSERT INTO foo VALUES (42)");
$result = sqlite_query($db,'select * from foo');
~~~
2016-12-29 11:25:39 +01:00