SQL命令
和MySQL一样,你可以使用一般的SQL命令来和SQLite数据库交换作用。SQLite所使用的准确的SQL语法列在http://sqlite.org/lang.html上面,但对大部分操作来说,SQL命令是标准的。
下面是一个例子,它建立了我将在本教程中使用的表格:
C:\WINDOWS\Desktop\sqlite>sqlite library.db
SQLite version 2.8.15
Enter ".help" for instructions
sqlite> create table books (
...> id integer primary key,
...> title varchar(255) not null,
...> author varchar(255) not null
...>);
sqlite> insert into books (title, author) values
('The Lord Of The Rings', 'J.R.R. Tolkien');
sqlite> insert into books (title, author) values
('The Murders In The Rue Morgue', 'Edgar Allen Poe');
sqlite> insert into books (title, author) values
('Three Men In A Boat', 'Jerome K. Jerome');
sqlite> insert into books (title, author) values
('A Study In Scarlet', 'Arthur Conan Doyle');
sqlite> insert into books (title, author) values
('Alice In Wonderland', 'Lewis Carroll');
sqlite> .exit
你可以通过SQLite命令行程序交互式或者非交互式的输入上述命令,SQLite命令行程序可以Windows和Linux平台下的编译好的二进制文件形式从http://sqlite.org/download.html中得到。SQLite 2.* 是当前用于PHP两个分支中的版本,同时SQLite 3.*预期支持PDO和之后的PHP5.*版本。
将下载的文件解压到你选择的一个目录中,在你的shell或者DOS窗口中用cd命令进入到该目录然后输入‘sqlite’。你可以看到SQLite版本信息和下面的一行:
Enter ".help" for instructions
请阅读http://sqlite.org/sqlite.html以获得更多的关于如何使用命令行程序的信息。
一旦将资料输入到数据库文件library.db中,立即运行SELECT查询以检查是否一切情况工作良好:
sqlite> select * from books;
1|The Lord Of The Rings|J.R.R. Tolkien
2|The Murders In The Rue Morgue|Edgar Allen Poe
3|Three Men In A Boat|Jerome K. Jerome
4|A Study In Scarlet|Arthur Conan Doyle
5|Alice In Wonderland|Lewis Carroll
如果你看到和上述输出一样的结果,那么你已经准备好可以出发了。