CodeIgniter Forums
PDO Help Needed - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: PDO Help Needed (/showthread.php?tid=63190)



PDO Help Needed - dharmender - 10-05-2015

I am unable to get PDO run in Codeigniter 3.0.1.
I have set up the PDO as it is in CI Docs, but unable to get it run.

Getting error.. $db undefined

Kindly help.


RE: PDO Help Needed - pdthinh - 10-05-2015

(10-05-2015, 06:05 AM)dharmender Wrote: I am unable to get PDO run in Codeigniter 3.0.1.
I have set up the PDO as it is in CI Docs, but unable to get it run.

Getting error.. $db undefined

Kindly help.

For PDO you should specify the DSN correctly. For example with MySQL:

PHP Code:
$db['default'] = array(

        'dsn'   => 'mysql:host=localhost;dbname=your_db_name',

 
       // remaining configs
); 



RE: PDO Help Needed - dharmender - 10-06-2015

I am getting the following error:
Fatal error: Call to undefined method CI_Loader::prepare()

Following are my configs:

$db['default']['dsn'] = 'mysql:host=localhost;dbname=db_name;charset=utf8;';

$db['default']['username'] = 'db_user';
$db['default']['password'] = 'db_pass';

$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
$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;


RE: PDO Help Needed - mwhitney - 10-07-2015

(10-06-2015, 12:16 AM)dharmender Wrote: I am getting the following error:
Fatal error: Call to undefined method CI_Loader::prepare()

What is the code you are using when this error occurs? It looks like you're trying to use the PDO::prepare() method, which isn't going to work with CI's DB class.