• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PDO in CodeIgniter 2.2.1

#1
Hi
I have tried to switch from mysql db driver to pdo and now I just got a blank white page with nothing on it and this in my php error log:
Code:
[16-Feb-2015 18:41:45 Europe/Berlin] PHP Fatal error:  Uncaught exception 'PDOException' with message 'invalid data source name' in /Applications/MAMP/htdocs/ignitercms/system/database/drivers/pdo/pdo_driver.php:114
Stack trace:
#0 /Applications/MAMP/htdocs/ignitercms/system/database/drivers/pdo/pdo_driver.php(114): PDO->__construct('mysql-srv1.khit...', 'ignitercms', 'ignitercms', Array)
#1 /Applications/MAMP/htdocs/ignitercms/system/database/DB_driver.php(115): CI_DB_pdo_driver->db_pconnect()
#2 /Applications/MAMP/htdocs/ignitercms/system/database/DB.php(148): CI_DB_driver->initialize()
#3 /Applications/MAMP/htdocs/ignitercms/application/third_party/MX/Loader.php(102): DB('', NULL)
#4 /Applications/MAMP/htdocs/ignitercms/system/core/Loader.php(1172): MX_Loader->database()
#5 /Applications/MAMP/htdocs/ignitercms/system/core/Loader.php(153): CI_Loader->_ci_autoloader()
#6 /Applications/MAMP/htdocs/ignitercms/application/third_party/MX/Loader.php(62): CI_Loader->initialize()
#7 /Applications/MAMP/htdocs/ignitercms/application/third_party/CMS/Loader.php(9): MX_Load in /Applications/MAMP/htdocs/ignitercms/system/database/drivers/pdo/pdo_driver.php on line 114
[16-Feb-2015 18:42:26 Europe/Berlin] PHP Fatal error:  Uncaught exception 'PDOException' with message 'invalid data source name' in /Applications/MAMP/htdocs/ignitercms/system/database/drivers/pdo/pdo_driver.php:114
Stack trace:
#0 /Applications/MAMP/htdocs/ignitercms/system/database/drivers/pdo/pdo_driver.php(114): PDO->__construct('mysql-srv1.khit...', 'ignitercms', 'ignitercms', Array)
#1 /Applications/MAMP/htdocs/ignitercms/system/database/DB_driver.php(115): CI_DB_pdo_driver->db_pconnect()
#2 /Applications/MAMP/htdocs/ignitercms/system/database/DB.php(148): CI_DB_driver->initialize()
#3 /Applications/MAMP/htdocs/ignitercms/application/third_party/MX/Loader.php(102): DB('', NULL)
#4 /Applications/MAMP/htdocs/ignitercms/system/core/Loader.php(1172): MX_Loader->database()
#5 /Applications/MAMP/htdocs/ignitercms/system/core/Loader.php(153): CI_Loader->_ci_autoloader()
#6 /Applications/MAMP/htdocs/ignitercms/application/third_party/MX/Loader.php(62): CI_Loader->initialize()
#7 /Applications/MAMP/htdocs/ignitercms/application/third_party/CMS/Loader.php(9): MX_Load in /Applications/MAMP/htdocs/ignitercms/system/database/drivers/pdo/pdo_driver.php on line 114

I know that my PHP configuration can work with PDO as I have done custom application with no framework and used PDO with no issues.

This is the content of config/database.php
PHP Code:
$active_group 'default';
$active_record TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'ci_app';
$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

There is nothing in the user guide related to using PDO under the database class.

I have found this project: https://github.com/cickes/PDOinCodeigniter2

But since there is a pdo driver in CI 2.2.1 I would think that it is actually supported, so there should be no need to replace the DB.php in the core.

Any suggestion on how to fix this?
Reply

#2
Use mysqli or upgrade to 3.0rc2.

PDO support in CI2 was experimental and as such has a lot of issues. With CI's abstractions on top of it, you gain nothing from using PDO anyway ... People will recommend it to you because it's easier to use on its own, but you're not accessing it directly.
Reply

#3
hi

PHP Code:
$db['default']['hostname'] = 'mysql:host=localhost;dbname=root;';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'ci';
$db['default']['dbdriver'] = 'pdo'


file attach onwrite in path :

Code:
system\database\drivers


Attached Files
.zip   pdo.zip (Size: 8.92 KB / Downloads: 510)
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.