sqlsqliteconfigurationkohanakohana-3

How to configure SQLite in Kohana 3?


I'm struggling to find any information on how to configure SQLite in Kohana 3.2. I mainly need to know:

This is my current configuration options:

'exportedDatabase' => array
(
    'type'       => 'sqlite',
    'connection' => array(
        /**
         * The following options are available for MySQL:
         *
         * string   hostname     server hostname, or socket
         * string   database     database name
         * string   username     database username
         * string   password     database password
         * boolean  persistent   use persistent connections?
         *
         * Ports and sockets may be appended to the hostname.
         */
        'hostname'   => $hostname,
        'database'   => $database,
        'username'   => $username,
        'password'   => $password,
        'persistent' => FALSE,
    ),
    'table_prefix' => '',
    'charset'      => 'utf8',
    'caching'      => FALSE,
    'profiling'    => TRUE,
),

Solution

  • As I found out, Kohana 3.x doesn't actually support SQLite. There's an unsupported module for it and, as far as I can tell, it's not working.

    It's easy enough to use PDO though and the syntax is pretty much the same as Kohana's ORM:

    $db = new PDO('sqlite:' . $dbFilePath);
    
    $query = $db->prepare('CREATE TABLE example (id INTEGER PRIMARY KEY, something TEXT)');
    $query->execute();
    
    $query = $db->prepare("INSERT INTO example (id, something) VALUES (:id, :something)");
    $query->bindParam(':id', $id);
    $query->bindParam(':something', $something);
    $query->execute();