开发者

Parsing SQLite3 in PHP

开发者 https://www.devze.com 2022-12-20 02:19 出处:网络
I\'ve got 开发者_Go百科an SQLite3 file which I\'d like to parse using PHP, but I\'d rather not have to go to the trouble of loading it into a database which I\'d first have to install on my server. Is

I've got 开发者_Go百科an SQLite3 file which I'd like to parse using PHP, but I'd rather not have to go to the trouble of loading it into a database which I'd first have to install on my server. Is there any library or function in PHP which allows for the direct parsing of SQLite3 from text or a file?


SQLite is an embedded database engine, so there's nothing you need to install except the sqlite3 extension.

Opening the database is as simple as:

<?php
$db = new SQLite3('my_database_file.db');


I honestly doubt that the "effort" to install SQLite is comparable to "parsing the file" regardless of the language used.

I suggest you install it and look if a client like Squirrel isn't appropriate for your needs. At worst it will take you a whole 10 minutes to install both, and if it is not what you are looking for you have wasted... 10 minutes.


I prefer the procedural approach when using sqlite library. Here's an example:

<?php 
// create new database (procedural interface) 
$db = sqlite_open("database.db"); 

// create a new database
sqlite_query($db , "CREATE TABLE foo (id INTEGER PRIMARY KEY, name CHAR(50))"); 

// insert sample data 
sqlite_query($db, "INSERT INTO foo (name) VALUES ('name1')"); 
sqlite_query($db, "INSERT INTO foo (name) VALUES ('name2')"); 
sqlite_query($db, "INSERT INTO foo (name) VALUES ('name3')"); 

// execute query 
$result = sqlite_query($db, "SELECT * FROM foo"); 
// iterate through the retrieved rows 
while ($row = sqlite_fetch_array($result)) { 
    print_r($row); 
} 

// close database connection 
sqlite_close($db); 

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消