Welcome Guest, Not a member yet? Register   Sign In
Problem connecting to sqlite database

Hi good CI people,

I hate for my first post to be a cry for help, rather than something more positive, but needs must... I've just started using CI and am trying to connect to my SQLite database. Here is my setup.

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "<path to sqlite db>/test.db";
$db['default']['dbdriver'] = "sqlite";
(of course, replace "&lt;path to sqlite db&gt;" with my actual path)
class Test_controller extends Controller {

    function index()
        echo "test 1";
        echo "test 2";

I can see "test 1" on my page, but not "test 2". I don't get any error messages or anything. "test.db" is readable by everybody. Any suggestions?

You might want to turn on error reporting if it is disabled:
Also, try logging an error to see if the load->database is even returning.


Thanks for your suggestions Jondolar. I checked my main "index.php" file and I still have the default:
I'm not sure what you mean by "logging an error". It seems clear to me that
is not returning, as "test 2" is not displayed.

He he he... Progress! First, I used
apt-get install php5-sqlite
to add an sqlite PDO driver to PHP. This appears to have done some good. Wow! apt-get is useful for something after all!? Now I get a rather useful error message:
A Database Error Occurred unable to open database: /var/www/CodeIgniter_1.7.1/&lt; my path&gt;
this shows me that CI has prefixed "/var/www/CodeIgniter_1.7.1/" to my database path. I had put my database in another directory for security reasons. I should be able to fix this now :coolsmile:

OK, so rather than using "~" in my path, I started with "/home/..." CI got the picture and didn't prefix my path. Unfortunately, I still got an error:
A Database Error Occurred
file is encrypted or is not a database
This feels like progress though. The thread:
http://ellislab.com/forums/viewthread/88885/ and the wiki
http://codeigniter.com/wiki/PDO_SQLite3/ suggests an alternative approach, using PDO as a database driver. In this approach, database.php would have:
$db['default']['database'] = "sqlite:/<path to database>/test.db3";
$db['default']['dbdriver'] = "pdo";
I will try this now as I have PDO working in straight PHP.

OK! After following the instructions at
including all the extra files, and making the suggested changes to database.php, I finally got everything working!
I guess PDOs are a nice generic way of working with databases. I really don't like the look of some of the hacks in "pdo_driver.php" though.
I also think it sucks that it is so difficult to get CI working with sqlite3! Surely sqlite is a more appropriate "default" database!?

Theme © iAndrew 2016 - Forum software by © MyBB