Home > php教程 > php手册 > body text

PHP中使用SQLite快速上手教程

WBOY
Release: 2016-05-26 08:20:08
Original
918 people have browsed it

SQLite是一款小巧轻型的数据库,支持的SQL语句不会逊色于其他数据库,支持的程序语言有Tcl、C#、PHP、Java等,现在我们来学习在PHP中如何使用SQLite.

一、如何建立文件夹:

SQLite会自动判断,文件夹是否存在,如果不存在才会建立.

try{ 
	$db_conn = new PDO('sqlite:mydb.sqlite'); 
}catch(PDOException $e){ 
	echo 'Error'; 
} 
$stmt = "CREATE TABLE mytable(id, user)"; 
$db_conn->exec($stmt);
Copy after login

二、如何写入文件:

使用方式和 MySQL 差不多.

$stmt = "INSERT INTO mytable(id, user) VALUES('1', 'AAA')"; 
$db_conn->exec($stmt);
Copy after login

三、如何使用资料:

使用方式和 MySQL 差不多.

$sth = $db_conn->prepare("SELECT id, user FROM mytable"); 
	$sth->execute();  
	while($row = $sth->fetch(PDO::FETCH_ASSOC)){ 
	echo $row['id'].':'.$row['user'].''; 
}
Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template