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);
二、如何写入文件:
使用方式和 mysql 差不多.
$stmt = insert into mytable(id, user) values('1', 'aaa'); $db_conn->exec($stmt);
三、如何使用资料:
使用方式和 mysql 差不多.
$sth = $db_conn->prepare(select id, user from mytable); $sth->execute(); while($row = $sth->fetch(pdo::fetch_assoc)){ echo $row['id'].':'.$row['user'].''; }
本文地址:
转载随意,但请附上文章地址:-)