SQLite是一款小巧輕型的數(shù)據(jù)庫,支持的SQL語句不會(huì)遜色于其他數(shù)據(jù)庫,支持的程序語言有Tcl、C#、PHP、Java等,現(xiàn)在我們來學(xué)習(xí)在PHP中如何使用SQLite.
一、如何建立文件夾:
SQLite會(huì)自動(dòng)判斷,文件夾是否存在,如果不存在才會(huì)建立.
- 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(); //開源軟件:Vevb.com
- while($row = $sth->fetch(PDO::FETCH_ASSOC)){
- echo $row['id'].':'.$row['user'].'';
- }
新聞熱點(diǎn)
疑難解答