爱程序网

php读取sqlite数据库入门实例

来源: 阅读:

php读取sqlite数据库的例子,php编程中操作sqlite入门实例.
原文参考:http://www.jbxue.com/article/php/22383.html
在使用SQLite前,要确保php.ini中已经启用sqlite和pdo配置

打开PHP.INI文件,打下以下扩展:
extension=php_pdo.dll

extension=php_pdo_sqlite.dll
extension=php_sqlite.dll
sqlite_open命令是打开一个数据库文件。
如果没有文件则创建。

sqlite_query可以执行SQL语句。
创建一个表并插入数据。

sqlite_unbuffered_query发出SELECT语句。
循环并显示结果。

unable to open a temporary database file for storing temporary tables
无法打开存储临时表的临时数据库文件,在Windows环境中,如果出现上述错误,
请使用putenv("TMP=C:/temp");指定临时文件夹。

具体请看代码:

<?php//临时目录 在Windows环境中,如果出现上述错误,请使用putenv("TMP=C:/temp");指定临时文件夹。//putenv("TMP=C:/temp");//打开数据库 www.jbxue.comif ($db = sqlite_open("test.db",0666,$sqliteerror)) {//创建表sqlite_query($db, "create table user(id integer primary key,name text);");//INSERT语句$sql = "insert into user values(NULL, '名字')";//执行SQL语句$res = sqlite_query($db, $sql);//SELECT语句$sql = "select * from user order by id desc limit 20";//执行SQL语句$res = sqlite_unbuffered_query($db, $sql);//显示结果while ($item = sqlite_fetch_array($res, SQLITE_ASSOC)) {print "ID:".$item["id"] ."NAME:".$item["name"];print "<BR>";};//关闭数据库sqlite_close($db);} else {print $sqliteerror;}?>

相关文章列表: