Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to access sqlite database in read mode using php

Tags:

php

sqlite

Couple questions. Whats the best way to access a live .db file using sqlite to just read data?

Secondly

$url = "data.db";

try

{

$db = new PDO('sqlite:"$url"');

...

How can I correct this syntax so I can set the database url as a variable? If I must use a different method other than PDO because of question 1 please set it out with a variable for database url.

Thanks

like image 223
Michael Avatar asked Oct 14 '25 04:10

Michael


1 Answers

Shamelessly taken from Opening SQLite3 as READONLY with PDO?:

Instead of PDO, try the SQLite3 library:

$db = new SQLite3($url, SQLITE3_OPEN_READONLY);

For more details, refer to PHP's doc:

http://php.net/manual/en/sqlite3.open.php


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!