tags:

views:

1902

answers:

4
+3  Q: 

CakePHP SQLite

Hi all! I have a rather basic problem: I can't seem to connect CakePHP to my SQLite database. Surprisingly, I didn't find lots of information about it on the internet, though I may be looking up the wrong keywords. Nevertheless, this is my connection code:

var $default = array(
  'driver' => 'sqlite',
  'connect' =>'sqlite_popen',
  'persistent' => false,
  'host' => 'localhost',
  'port' => '',
  'login' => '',
  'password' => '',
  'database' => '/home/MY_USER_NAME/public_html/my_database.sqlite',
  'schema' => '',
  'prefix' => '',
  'encoding' => ''
);

Still, Cake only says "Cake is NOT able to connect to the database". Also, I don't know where to see the "real" logs (i.e., the error returned from the SQLite "driver"). So, I hit a dead-end. What should I do?

Thanks in advance.

+1  A: 

Are you trying to connect to a SQLite 3 database? CakePHP doesn't support them yet.

Other than that, you might want to try adding the leading / in your path. Seems like you're trying to do an absolute path but without the leading slash it's not going to do what you think it's going to do.

Paolo Bergantino
Added de leading slash, just forgot it when typing the path here (I retyped the path with names changed to protect the innocent). I heard about the SQLite 3 issue, but I don't know what is the version of the database I created, didn't see this option in the IDE (I'm using Firefox's Extension SQLite Manager). How do I find it out?
Rafael Almeida
"select sqlite_version()" will show you the version of the sqlite engine in use.
Alex Martelli
Solved the problem by giving up on the SQLite Manager, downloading the SQLite 2 database, getting my hands dirty and coding the database myself.
Rafael Almeida
No need to drop back to SQLite2. The link provided by Paolo shows that SQLite3 support has been changed from "bug" to "enhancement" and scheduled for CakePHP 2.0.x.x. In the meantime, you can use the driver attached to the ticket.
gidmanma
+6  A: 

SQLite3 is not officially supported yet by CakePHP... probably because the file attached to this bug/enhancement works.

https://trac.cakephp.org/ticket/3003

Grab the latest version of the file, update it with any newer patches, upload it to your cake/libs/model/datasources/dbo directory and configure it in your database.php file.

I am using a file called dbo_sqlite3.php

My configuration file uses this for the driver setting:

  'driver' => 'sqlite3',
gidmanma
It's nice to know that, I might use it in future projects! Thanks!
Rafael Almeida
A: 

Posted a howto Trac solution and another one for using sqlite3 with Cakephp 1.2.x at http://gacimartin.com/2009/11/15/como-utilizar-sqlite3-en-cakephp-1-2/

Carlos
+1  A: 

How to CakePHP with SQLite3:

Requirments:

Steps:

Unpack the Datasources plugin in place.

Edit dbo_sqlite3.php and add:

App::import('Datasource','DboSource');

...just before the 'class' definition.

Use the following configuration in your database.php file:

var $default = array(
    'datasource' => 'Datasources.DboSqlite3',
    'login' => '',
    'password' => '',
    'database' => '/full/path/to/db.sqlite');

Done.

anonymous
Yep, by now it's easy already =D the problem was that these weren't available when this question was posted. Voting up for the reference anyway. =)
Rafael Almeida