Sandeep
Sandeep

Reputation: 21144

Using sqlite with codeigniter strange error

I am trying to use the sqlite database with codeigniter. I created a table in it and then loaded the database in the config file as;

$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'sqlite';
$db['default']['dbprefix'] = '';

And autoloaded the db library in autoload.php but the view that I render from the controller is blank even does not display any error. When I do not autoload this file then the viw renders correctly. I am not sure what is the problem here.

Upvotes: 1

Views: 1887

Answers (2)

John Reid
John Reid

Reputation: 1185

CI2 has changed a few bits. First of all you need the sqlite protocol and path in the 'hostname' parameter, and you need to set the dbdriver as 'pdo'. Oh, and you obviously need the PDO sqlite driver installed on the server:

$db['default']['hostname'] = 'sqlite:/var/my.db';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = '';

There is also a bug in the release I downloaded which casuses DB errors to be thrown incorrectly. If you have this, google the output with PDO exception and you should find the bug. Hope that helps.

Upvotes: 5

jere
jere

Reputation: 4304

you should check this out: PDO SQLite3 in CodeIginter

Upvotes: -1

Related Questions