Welcome Guest, Not a member yet? Register   Sign In
Can't Connect To SQLlite 3 Datbase Using SQLlite or PDO Drivers
#1

[eluser]Vheissu[/eluser]
I can't seem to get Codeigniter (latest version from Github) to work with my SQLlite3 database. I get the error: "file is encrypted or is not a database" system\database\drivers\sqlite\sqlite_driver.php on line number 78. Is this a known issue and are there any ways around this?

When I create a SQLlite 2 database and try connecting to it I get further and get the following:

Severity: Notice
Message: Undefined property: Welcome::$db
Filename: libraries/Session.php
Line Number: 210

Connecting via PDO also throws errors about not being able to find a driver or something.
#2

[eluser]toopay[/eluser]
If you use the latest state of develop branch, you could not use the native driver. Someone has been submitted a pull request regarding SQLite3 native driver, but it will take a while to get those pull merged.

So for now, you could use SQLite2/3 with the PDO, by this prototype :
Code:
$db['testing_sqlite']['dsn'] = 'sqlite:/path/to/db.sqlite';
Take a look at this configuration for more PDO example.
#3

[eluser]Vheissu[/eluser]
Toopay thanks for replying so fast man. It appears that the above didn't work though. My code looks like this in the database.php file. My database file is in: application/db/ and called lucifer.db.

Code:
$db['sqlite']['dns'] = 'sqlite:/'.APPPATH.'/db/lucifer.db';
$db['sqlite']['hostname'] = '';
$db['sqlite']['username'] = '';
$db['sqlite']['password'] = '';
$db['sqlite']['database'] = '';
$db['sqlite']['dbdriver'] = 'pdo';
$db['sqlite']['dbprefix'] = '';
$db['sqlite']['pconnect'] = FALSE;
$db['sqlite']['db_debug'] = FALSE;
$db['sqlite']['cache_on'] = FALSE;
$db['sqlite']['cachedir'] = '';
$db['sqlite']['char_set'] = 'utf8';
$db['sqlite']['dbcollat'] = 'utf8_general_ci';
$db['sqlite']['swap_pre'] = '';
$db['sqlite']['autoinit'] = TRUE;
$db['sqlite']['stricton'] = FALSE;

I appear to get a fatal error from the above aforementioned code:

Code:
Fatal error: Uncaught exception 'PDOException' with message 'invalid data source name' in C:\xampp\htdocs\lucifer\system\database\drivers\pdo\pdo_driver.php:113 Stack trace: #0 C:\xampp\htdocs\lucifer\system\database\drivers\pdo\pdo_driver.php(113): PDO->__construct(';dbname=', '', '', Array) #1 C:\xampp\htdocs\lucifer\system\database\DB_driver.php(127): CI_DB_pdo_driver->db_connect() #2 C:\xampp\htdocs\lucifer\system\database\DB.php(148): CI_DB_driver->initialize() #3 C:\xampp\htdocs\lucifer\application\third_party\MX\Loader.php(96): DB('', NULL) #4 C:\xampp\htdocs\lucifer\system\core\Loader.php(1172): MX_Loader->database() #5 C:\xampp\htdocs\lucifer\system\core\Loader.php(153): CI_Loader->_ci_autoloader() #6 C:\xampp\htdocs\lucifer\system\core\Controller.php(59): CI_Loader->initialize() #7 C:\xampp\htdocs\lucifer\application\third_party\MX\Base.php(55): CI_Controller->__construct() #8 C:\xampp\htdocs\lucifer\application\third_party\MX\Base.php(60): CI->__construct() #9 C:\xampp\htdocs\lucifer\application\third_party\MX\ in C:\xampp\htdocs\lucifer\system\database\drivers\pdo\pdo_driver.php on line 113
#4

[eluser]toopay[/eluser]
From this build process i know that the recent PDO code works fine with SQLite3, so the problem may be one (or some) of this following reasons :
- Your path is not pointed correctly to your SQLite database. To resolve, check using file_exists against the path.
- Your file ownership (and also permission, if necessary), should be correctly allow PHP to work with it. To resolve, use (if you are in Ubuntu or other Unix OS) :
Code:
cd /path/to/your/db
sudo chown www-data db_name.db

From above configuration you posted, at least this part :
Code:
$db['sqlite']['dns'] = 'sqlite:/'.APPPATH.'/db/lucifer.db';
// You should use 'dsn' instead 'dns'
// Also, this will generate some path like : 'application//db/lucifer.db'
should be
Code:
$db['sqlite']['dsn'] = 'sqlite:/'.APPPATH.'db/lucifer.db';
#5

[eluser]Vheissu[/eluser]
Thanks for helping Toopay, I feel we're really getting closer here. Those above errors are gone using this line:
Code:
$db['sqlite']['dns'] = 'sqlite:'.APPPATH.'db/lucifer.db';

However I am now getting the error below:

Code:
Invalid DB Connection String for PDO

All permissions are correct, I'm using XAMPP on a Windows machine, so no CHOWN'ing or anything required.
#6

[eluser]toopay[/eluser]
You need to use 'dsn' instead 'dns'.
Yes, i know anyone perhaps did not hear it since this is new param available on database.php, so anyone could easily misspeled.
#7

[eluser]Vheissu[/eluser]
Ah, thanks mate that got rid of the above error. I'm probably going to drive you insane with this, but I'm not getting another error.

"Fatal error: Call to a member function quote() on a non-object in C:\xampp\htdocs\lucifer\system\database\drivers\pdo\pdo_driver.php on line 475"

I appreciate the help btw.
#8

[eluser]toopay[/eluser]
That mean there is still an issue on your PDO connection, since quote is a PDO method.

Are you autoload your database? If not, what method you use, which generate those error in your model?

Also, you could do this simple test, to check whether your current database.php working or not, for PDO sqlite case :
Code:
// in some controller
function pdosqlite()
{
   // If you did not autoload database, add :
   // $this->load->database();
   echo 'My database existance status : ';
   var_dump(file_exists(strpbrk($this->db->dsn, '/')));
   echo '<hr />';
   echo 'My PDO connection status : ';
   var_dump($this->db->conn_id instanceof PDO);
}




Theme © iAndrew 2016 - Forum software by © MyBB