Welcome Guest, Not a member yet? Register   Sign In
codeigniter 2.1.3 and sqlite 3 doesn't work
#1

[eluser]Unknown[/eluser]
Hi ,
I'm trying to work with sqlite , I follow the instruction in the following blog http://khromov.wordpress.com/2012/06/22/...databases/
but when I request any page I get :
Quote:Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /var/www/eit/system/database/drivers/pdo/pdo_driver.php:114 Stack trace: #0 /var/www/eit/system/database/drivers/pdo/pdo_driver.php(114): PDO->__construct('sqlite:/applica...', '', '', Array) #1 /var/www/eit/system/database/DB_driver.php(115): CI_DB_pdo_driver->db_pconnect() #2 /var/www/eit/system/database/DB.php(148): CI_DB_driver->initialize() #3 /var/www/eit/system/core/Loader.php(346): DB('', NULL) #4 /var/www/eit/system/core/Loader.php(1171): CI_Loader->database() #5 /var/www/eit/system/core/Loader.php(152): CI_Loader->_ci_autoloader() #6 /var/www/eit/system/core/Controller.php(51): CI_Loader->initialize() #7 /var/www/eit/application/controllers/main.php(13): CI_Controller->__construct() #8 /var/www/eit/system/core/CodeIgniter.php(308): Main->__construct() #9 /var/www/eit/index.php(202): require_once('/var/www/eit/sy...') #10 {main} thrown in /var/www/eit/system/database/drivers/pdo/pdo_driver.php on line 114

my databas.php file :
Code:
$active_group = 'default';
$active_record = TRUE;


$db['default']['hostname'] = 'sqlite:/'.APPPATH.'db/eit.sqlite';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

my sqlite db located in : application/db/eit.sqlite.

please help Smile
#2

[eluser]TheFuzzy0ne[/eluser]
Are you sure you have the SQLite PDO driver installed?
#3

[eluser]Unknown[/eluser]
I'ts wasn't I installed it and now it's working , thanks for reply ..
#4

[eluser]marega[/eluser]
I am having the same issue. How do I install the SQLite PDO driver?
#5

[eluser]TheFuzzy0ne[/eluser]
It should be a PHP extension that needs to be enabled. What server environment are you running?
#6

[eluser]marega[/eluser]
Oh, i see.

I am using xampp 2.5. The thing is. Ive managed to get SqLite working just fine running TinyMVC: https://github.com/eimg/tinymvc
So, the server environment seem to be able to handle Sqlite.

Its very confusing. Any leads is much appreciated.
#7

[eluser]TheFuzzy0ne[/eluser]
Hmm... Please post your ./application/config/database.php file (remove any sensitive information first).
#8

[eluser]marega[/eluser]
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql.  Currently supported:
     mysql, mysqli, postgre, odbc, mssql, sqlite, oci8
| ['dbprefix'] You can add an optional prefix, which will be added
|     to the table name when using the  Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
|     NOTE: For MySQL and MySQLi databases, this setting is only used
|      as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
|     (and in table creation queries made with DB Forge).
|      There is an incompatibility in PHP with mysql_real_escape_string() which
|      can make your site vulnerable to SQL injection if you are using a
|      multi-byte character set and are running versions lower than these.
|      Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
|       - good for ensuring strict SQL while developing
|
| The $active_group variable lets you choose which connection group to
| make active.  By default there is only one group (the 'default' group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'sqlite:/'.APPPATH.'db/db.sqlite';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


/* End of file database.php */
/* Location: ./application/config/database.php */
#9

[eluser]TheFuzzy0ne[/eluser]
OK, I think the next sensible step to take would be to create a controller that calls phpinfo(). Does that mention anything about SQLite?
#10

[eluser]Unknown[/eluser]
Hi there,

I'm new here and was just investigating, if CI is something for me. I'm not even a PHP-developer, therefore I need something easy ;-)

Since I work mostly with SQLite-databases, I first tried to get CI to work with pretty vanilla SQLite... But it has it's problems. I'm sporting the same error as above: I can query the database (mostly) fine, but as soon as I try to create tables or make some database management I get this exception:

Fatal error: Call to a member function execute() on a non-object in /Users/andy/Sites/admin-pro/system/database/drivers/pdo/pdo_driver.php on line 193

A quick look at CI's pdo_driver shows, that it's not really like I imagined, a pdo driver would be For instance, it calls 'Show Columns' on an internal function. But this SQL-statement is MySQL only.
Code:
function _list_columns($table = '')
{
return "SHOW COLUMNS FROM ".$table;
}
I think it would be better to
Code:
function _list_columns($table = '')
{
   if ($db->dbdriver == "pdo" && $db == "sqlite" || $db->dbdriver == "sqlite")
{
        return "PRAGMA table_info( {$tableName} )";
    } else {
        return "SHOW COLUMNS FROM ".$table;
    }
}
Maybe someone with more PHP experience can look into the pdo-driver and help us newbies to get CI up and running with SQLite... (it's a shame, that it doesn't do that naturally Wink)

Using a external database-management tool is not an option for me, since I need to create tables and fields from within my UI.

Cheers

andy




Theme © iAndrew 2016 - Forum software by © MyBB