0

I have a server with just one available database, and I'm making a tiny webapp that would also like to have a database.

Do I need to use an special setting or workaround to make CodeIgniter work with a file-based database? Or just put "sqlite3" as the database driver and hope for the best?

halfer
  • 19,824
  • 17
  • 99
  • 186
DarkGhostHunter
  • 1,521
  • 3
  • 12
  • 23
  • I wouldn't recommend you just "hope for the best" with any configuration, if you value your data! Does CodeIgniter allow you to connect to PDO databases? If so, then SQLite should be supported - have you tried it? – halfer Jul 21 '15 at 22:45
  • [See here](http://stackoverflow.com/q/8326198/472495), looks like the driver is `sqlite`. – halfer Jul 21 '15 at 22:46
  • I can use [PDO as database driver](http://www.codeigniter.com/userguide3/database/connecting.html?highlight=pdo), but I don't know if MySQL is a requirement at all with PDO, and where to put a path for the database file. – DarkGhostHunter Jul 21 '15 at 22:51
  • Always [RTFM](http://www.codeigniter.com/userguide3/database/configuration.html#explanation-of-values). > Depending on what database platform you are using (MySQL, PostgreSQL, etc.) not all values will be needed. For example, when using SQLite you will not need to supply a username or password, and the database name will be the path to your database file. The information above assumes you are using MySQL. – Tpojka Jul 21 '15 at 23:07
  • @DarkGhostHunter: the path for the database file is shown on the post I linked to - I don't know if that's right, but it's worth a try. PDO in itself does not require MySQL, it is database-agnostic. I don't know what restrictions CodeIgniter has, though. – halfer Jul 21 '15 at 23:29
  • Im gonna try to build something with PDO and sqlite. – DarkGhostHunter Jul 22 '15 at 00:25

1 Answers1

0

I did it. In CodeIgniter 3, btw, so some details about PDO->SQLite3 can be worked on.

In database.php, select pdoas dbdriver, and in the dsn entry put 'sqlite:PATH_TO_YOUR_DB'. In my webapp, I decided to use 'sqlite:' . BASEPATH . 'mydatabase.sql'. Thats all, CodeIgniter 3 will use that file as a database.

If that doesn't work, you should see if your php.ini has extension=php_pdo_sqlite.dll uncommented, otherwise it will show errors.

DarkGhostHunter
  • 1,521
  • 3
  • 12
  • 23