Using PDO (MySQL) in CodeIgniter 2.x.x

August 31, 2013 by Andrew Seymour

PDO is pretty helpful – most frameworks have a Database driver and subclasses that people need to write in order to get that specific database working (things like ORM/ActiveRecord still need these) but essentially that’s what PDO is except it’s an extension to PHP.

PDO support is in CodeIgniter 2.x.x however, the database config needs a little bit of tweaking so if you get;

Fatal error:  Uncaught exception ‘PDOException’ with message ‘invalid data source name’ in

When switching the driver type to “pdo” then it probably means that, your hostname is;

$db['default']['hostname'] = '';

Which needs to be;

$db['default']['hostname'] = '';

Perhaps in later versions of CI this is fixed – maybe a solution is for the driver to be “pdo-mysql” and do it that way – anyway, that’s the temporary fix which works fine.

Categories: Uncategorized