How do i connect to a sqlite database? I am planning to distribute a db with my application with all the tables already made in it, so i don't need to create a new db or tables, just distribute it.
I so far have experience with mysql where i have used connection strings like
<?php session_start();
// DATABASE CONNECTION
$hostname = 'localhost';
$dbname = 'xxxxxxxxxxxx';
$username = 'xxxxxxxxxxxx';
$password = 'xxxxxxxxxxxx';
// Let's connect to host
mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
// Select the database
mysql_select_db($dbname) or DIE('Database name is not available!');
?>
After the connection is established i go about my business of inserting > selecting > deleting and updating table values using mysql_query and mysql_fetch_array etc.
but how is this process different in SQLITE. all help is appreciated. i am new to sqlite.
Sqlite is a lighter form for sql, it doesn't have a server/client. So you directly "connect" to the file(or inmemory).
You can connect to the memory(which will be flushed after restart of application) by $db = sqlite3_open(":memory:");
or to a file called "mydatabase.db" with $db = sqlite3_open("mydatabase.db");
.
More info at http://www.php.net/manual/en/intro.sqlite3.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.