PDA

View Full Version : How to enable sqlite3 with the php5.3?



Newbie89
March 13th, 2013, 01:51 PM
I have look so many type of enable...but I still not very clear about on how to enable them...
Can show me some clear step?Thanks...

greenpeace
March 13th, 2013, 03:23 PM
Hey

Do you have sqlite library for php installed on your system?


sudo apt-get install php5-sqlite

Cheers,
Gp

Newbie89
March 14th, 2013, 01:57 PM
Ya...I already install...I want to know whether the version now support PDO only?

greenpeace
March 14th, 2013, 09:48 PM
Hey,

No, you can use the SQLite3 class to do it.

First, check that you've reloaded Apache after installing:


sudo service apache2 reload

Then you can test it with the following code, which you can put in /var/www/test-sqlite.php (or whatever you like) and then run it in your browser.


<?php

// open the db file (test.db) if it exists, or create it if it doesn't
$db = new SQLite3('test.db');

// create a new table in the file
$db->exec('CREATE TABLE test (id INT, message STRING)');

// insert some things into it.
$db->exec("INSERT INTO test (id, message) VALUES ('1', 'test message')");
$db->exec("INSERT INTO test (id, message) VALUES ('2', 'test message 2')");

// make a select
$results = $db->query("SELECT * FROM test WHERE ID = 2");

// print some results
print_r($results->fetchArray());

?>

Check your /var/www/apache2/error.log for errors, and check that apache has permissions to write to the directory where it will create the DB file. This problem should be obvious from the logs.


Good luck,
Gp