Welcome Guest, Not a member yet? Register   Sign In
Trying to connect to SQLite database
#1

[eluser]imorris[/eluser]
I'm using CI 1.73 and the SQLite DB driver (http://codeigniter.com/wiki/PDO_SQLite3/) to connect to a sqlite database.

I can successfully connect to the database using plain php code:

Code:
<p>PDO TEST: SQLITE 3.x</p>
&lt;?php        
$connection = new PDO('sqlite:/home/hci/LabResend');    
$handle = $connection->query("SELECT * FROM tbl1");      
if($handle){        
    $result = $handle->fetchAll(PDO::FETCH_ASSOC);        
    print("<pre>".print_r($result,true)."</pre>");    
}else{        
    var_dump($connection->errorInfo());        
    print("query returned negatively");    
} ?&gt;

...but I can't connect to the database using Codeigniter's database driver. Can someone help?

Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = 'sqlite:'./database/LabResend';
$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
#2

[eluser]imorris[/eluser]
Good news, I got connected to my database. My problem was because of the database being in the wrong path. Now, my problem is that when I use active records to run a basic "select" statement I get the following error:


A Database Error Occurred

Error Number: 1

unsupported file format

SELECT * FROM tbl1

I used the sqlite instructions to setup my test database. I don't know why I'm getting this error. Any thoughts?

Here's the instructions I used to create the database. I can successfully run SQL statements against it manually.

http://www.sqlite.com/sqlite.html
#3

[eluser]tanero[/eluser]
I don't know why the sqlite database is so problematic, but it seems your problem related to version of sqlite database. your are trying to connect by sqlite3 driver to sqlite2 db.
#4

[eluser]imorris[/eluser]
[quote author="tanero" date="1300028310"]I don't know why the sqlite database is so problematic, but it seems your problem related to version of sqlite database. your are trying to connect by sqlite3 driver to sqlite2 db.[/quote] Thank you for your response. I did successfully get connected but it took some doing on my part. I had to upgrade PHP, install various PHP - SQLite extensions, and use the following server configuration to get connected:
Code:
$active_group = "messageresend";
$active_record = TRUE;

$db['messageresend']['hostname'] = "";
$db['messageresend']['username'] = "";
$db['messageresend']['password'] = "";
$db['messageresend']['database'] = 'sqlite:../path/to/SQLite.db';
$db['messageresend']['dbdriver'] = "pdo";
$db['messageresend']['dbprefix'] = "";
$db['messageresend']['pconnect'] = FALSE;
$db['messageresend']['db_debug'] = TRUE;
$db['messageresend']['cache_on'] = FALSE;
$db['messageresend']['cachedir'] = "";
$db['messageresend']['char_set'] = "utf8";
$db['messageresend']['dbcollat'] = "utf8_general_ci";




Theme © iAndrew 2016 - Forum software by © MyBB