How to install sqlite or sqlite 3 database with xampp server and how to use sqlite or sqlite 3 database using php scripts or programs...
phpLiteAdmin is for SQLite what phpMyAdmin is for MySQLphpLiteAdmin is a web-based SQLite database admin tool written in PHP with support for SQLite3 and SQLite2. Following in the spirit of the flat-file system used by SQLite, phpLiteAdmin consists of a single source file, phpliteadmin.
SQLite can be used with PHP scripts through the SQLite PHP functions. You can check the SQLite and PDO_SQLite library versions using the phpinfo function.
Select SQLite from the list. Give a Connection name for your own internal reference. For Database , click Choose a File and then select the database file on your local machine to which you want to connect. Hit Connect and you're all set!
To activate SQLite3 in Xampp (v3.2.2). Open xampp/php/php.ini
, un-comment the line ;extension=sqlite3
(retrieve the ;), save the php.ini
and restart your Xampp server.
You have two possibilities to achieve that:
Writing your DDL-statements (CREATE TABLE...) in a .sql file and execute it using the sqlite command line (assuming your CREATE TABLE statements are in a file called tabledef.sql):
cat tabledef.sql | sqlite3 yourdbname.db
You should definitely use PDO to do that:
$dbh = new PDO('sqlite:/path/to/your/database.db', '', '', array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
));
If the database does not exist, then it is created. But you need write-access to the directory that contains the database. If you permit write-access only to the database file, sqlite fails because it also needs to create a lock file in the same directory.
Now that you have a connection you can do your stuff with the database, for example execute some DDL-statements:
$dbh->exec("CREATE TABLE IF NOT EXISTS mytable (
mypk INTEGER PRIMARY KEY AUTOINCREMENT,
myvalue TEXT);");
Or if you need to dynamically generate SQL statements, use prepared statements:
$statement = $dbh->prepare("INSERT INTO mytable (myvalue) VALUES(?)");
$statement->execute(array("hello"));
$statement->execute(array("world"));
This is only a small overview, for further information you should check out the PDO manual and the sqlite Documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With