2013-11-12
官方網站
http://www.sqlite.org/
相關文件
http://www.sqlite.org/docs.html
安裝很簡單
yum -y install sqlite
測試
[root@localhost ~]# sqlite3
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .help
.backup ?DB? FILE Backup DB (default "main") to FILE
.bail ON|OFF Stop after hitting an error. Default OFF
.databases List names and files of attached databases
.dump ?TABLE? ... Dump the database in an SQL text format
If TABLE specified, only dump tables matching
LIKE pattern TABLE.
.echo ON|OFF Turn command echo on or off
.exit Exit this program
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
.genfkey ?OPTIONS? Options are:
--no-drop: Do not drop old fkey triggers.
--ignore-errors: Ignore tables with fkey errors
--exec: Execute generated SQL immediately
See file tool/genfkey.README in the source
distribution for further information.
.header(s) ON|OFF Turn display of headers on or off
.help Show this message
.import FILE TABLE Import data from FILE into TABLE
.indices ?TABLE? Show names of all indices
If TABLE specified, only show indices for tables
matching LIKE pattern TABLE.
.load FILE ?ENTRY? Load an extension library
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elements
.nullvalue STRING Print STRING in place of NULL values
.output FILENAME Send output to FILENAME
.output stdout Send output to the screen
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.schema ?TABLE? Show the CREATE statements
If TABLE specified, only show tables matching
LIKE pattern TABLE.
.separator STRING Change separator used by output mode and .import
.show Show the current values for various settings
.tables ?TABLE? List names of tables
If TABLE specified, only list tables matching
LIKE pattern TABLE.
.timeout MS Try opening locked tables for MS milliseconds
.width NUM NUM ... Set column widths for "column" mode
.timer ON|OFF Turn the CPU timer measurement on or off
sqlite> .quit
[root@localhost ~]#
建立資料測試
[root@localhost ~]# sqlite3 testdb <== 建立資料庫 testdb
SQLite version 3.6.20
Enter ".help" for instructions
sqlite> create table students(no, cname); <== 建議資料表 students, 兩個欄位 no 和 cname (欄位可以填入任何屬性)
sqlite> insert into students values ('01', 'John');
sqlite> insert into students values ('02', 'Mary');
sqlite> insert into students values ('03', 'Peter');
sqlite> select * from students; <== 查詢所有資料
01|John
02|Mary
03|Peter
sqlite> .quit
[root@localhost ~]#
資料庫備份
[root@localhost ~]# sqlite3 testdb.db ".dump" . testdb.sql
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
COMMIT;
[root@localhost ~]#
或
[root@localhost ~]# echo '.dump' | sqlite3 test.db | gzip -c > testdb.dump.gz
資料庫還原
[root@localhost ~]# sqlite3 testdb2.db . testdb.sql
或
[root@localhost ~]# zcat testdb.dump.gz | sqlite3 testdb2
查詢資料庫的 schema
[root@localhost ~]# sqlite3 testdb2.db
sqlite> .schema
CREATE TABLE students(no, cname);
sqlite> .database
seq name file
--- --------------- ----------------------------------------------------------
0 main
1 temp
sqlite> .tables
students
sqlite> select * from sqlite_master;
table|students|students|2|CREATE TABLE students(no, cname)
[root@localhost ~]#
更多的使用教學相關文件請看
http://www.sqlite.org/docs.html
yum 安裝雖然提供 sqlite,但是沒有提供 PHP + SQLite 的 php-sqlite 或 php-sqlite3 之類的套件
[root@localhost ~]# yum list | grep sqlite
qt-sqlite.x86_64 1:4.6.2-25.el6 @anaconda-CentOS-201303020151.x86_64/6.4
sqlite.x86_64 3.6.20-1.el6 @anaconda-CentOS-201303020151.x86_64/6.4
apr-util-sqlite.x86_64 1.3.9-3.el6_0.1 base
bacula-director-sqlite.x86_64 5.0.0-12.el6 base
bacula-storage-sqlite.x86_64 5.0.0-12.el6 base
libdbi-dbd-sqlite.x86_64 0.8.3-5.1.el6 base
qt-sqlite.i686 1:4.6.2-26.el6_4 updates
qt-sqlite.x86_64 1:4.6.2-26.el6_4 updates
qt3-sqlite.i686 3.3.8b-30.el6 base
qt3-sqlite.x86_64 3.3.8b-30.el6 base
sqlite.i686 3.6.20-1.el6 base
sqlite-devel.i686 3.6.20-1.el6 base
sqlite-devel.x86_64 3.6.20-1.el6 base
sqlite-doc.x86_64 3.6.20-1.el6 base
sqlite-tcl.x86_64 3.6.20-1.el6 base
[root@localhost ~]#
檢查一下目前編譯設定
[root@localhost ~]# yum -y install httpd php php-mysql mysql mysql-server
[root@localhost ~]# service mysqld restart
[root@localhost ~]# service httpd restart
[root@localhost ~]# vi /var/www/html/1.php
內容如下
<?php
phpinfo();
?>
用瀏覽器觀看 1.php 網頁,可以看到編譯 PHP 的參數
'./configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-sqlite' '--with-libxml-dir=/usr' '--enable-xml' '--with-system-tzdata' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--without-sqlite3' '--disable-phar' '--disable-fileinfo' '--disable-json' '--without-pspell' '--disable-wddx' '--without-curl' '--disable-posix' '--disable-sysvmsg' '--disable-sysvshm' '--disable-sysvsem'
可以看到 --without-sqlite 和 --without-sqlite3,表示編譯時不包含 sqlite
--with-sqlite 表示要讓安裝 PHP 時,要支援 SQLite
--with-apxs2=/usr/sbin/apxs 表示要讓安裝 PHP,要支援 Apache httpd
所以要讓 PHP 支援 SQLite,要自己下載 PHP 的 tarball 檔案,自己編譯,請看下面這篇
[研究] SQLite 3 + Httpd + PHP 安裝(tar.gz)(CentOS 6.4 x64)
http://shaurong.blogspot.tw/2013/11/sqlite-3-httpd-php-centos-64-x64.html
(完)
相關
[研究] SQLite 3.6.20 資料庫系統安裝(yum) (CentOS 6.4 x64)
http://shaurong.blogspot.tw/2013/11/sqlite-3620-centos-64-x64.html
[研究] SQLite 3 + Httpd + PHP 安裝(tar.gz)(CentOS 6.4 x64)
http://shaurong.blogspot.tw/2013/11/sqlite-3-httpd-php-centos-64-x64.html
[研究] SQLite 3 資料庫安裝(CentOS 5.5 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=19509
[研究] SQLite 3 + Httpd + PHP 安裝(CentOS 5.5 x86)
http://forum.icst.org.tw/phpbb/viewtopic.php?t=19558
沒有留言:
張貼留言