Hi everyone
I could use a little help in config. to get CI talking to my db using pdo.
I also have a few questions about (the necessity, for injection-safety?) of using pdo in CI.
I have a CI project/app for which I initially coded it using Active Record, and I just upgraded to using CI 2.1.1 so that I could rewrite my model files to use (the now CI-supported) PDO,
as given the climate in security threads on PHP forums, etc, - the professional climate is pressuring to move away from escaping and into PDO/bound parameters etc.
Anyway, I modified ‘application/config/database.php’ like so:
[snip]
$active_group = 'local_dev';
$active_record = TRUE;//<---will this need to stay TRUE to make CI sessions work? For better security, don't we want db-based CI sessions to use PDO too?
//http://ellislab.com/codeigniter/user-guide/database/configuration.html:
//Note: that some CodeIgniter classes such as Sessions require Active Records be enabled to access certain functionality.
//this is the config setting that I am guessing is my main problem: (?)
$db['local_dev']['hostname'] = 'localhost:/tmp/mysql.sock';
// 1.) if $db['local_dev']['dbdriver']='mysql', then here ^^^ 'localhost:/tmp/mysql.sock' works, 2.) but if $db['local_dev']['dbdriver']='pdo', then it fails with error msg. shown below.
$db['local_dev']['username'] = 'root';
$db['local_dev']['password'] = '';
$db['local_dev']['database'] = 'mydbname';
$db['local_dev']['dbdriver'] = 'pdo';
$db['local_dev']['dbprefix'] = '';
$db['local_dev']['pconnect'] = TRUE;
$db['local_dev']['db_debug'] = TRUE;//TRUE
$db['local_dev']['cache_on'] = FALSE;
$db['local_dev']['cachedir'] = '';
$db['local_dev']['char_set'] = 'utf8';
$db['local_dev']['dbcollat'] = 'utf8_general_ci';
$db['local_dev']['swap_pre'] = '';
$db['local_dev']['autoinit'] = TRUE;
$db['local_dev']['stricton'] = FALSE;
[snip]With the above config., as soon as I load a controller, I get this error message:
Fatal error: Uncaught exception ‘PDOException’ with message ‘could not find driver’ in
/Library/WebServer/Documents/system/database/drivers/pdo/pdo_driver.php:114 Stack trace: #0
/Library/WebServer/Documents/system/database/drivers/pdo/pdo_driver.php(114): PDO->__construct(‘localhost:/tmp/...’, ‘root’, ‘’, Array) #1 /Library/WebServer/Documents/system/database/DB_driver.php(115): CI_DB_pdo_driver->db_pconnect() #2
/Library/WebServer/Documents/system/database/DB.php(148): CI_DB_driver->initialize() #3
/Library/WebServer/Documents/system/core/Loader.php(346): DB(’‘, NULL) #4
/Library/WebServer/Documents/system/core/Loader.php(1171): CI_Loader->database() #5
/Library/WebServer/Documents/system/core/Loader.php(152): CI_Loader->_ci_autoloader() #6
/Library/WebServer/Documents/system/core/Con in
/Library/WebServer/Documents/system/database/drivers/pdo/pdo_driver.php on line 114
I tried swapping out the ‘pdo_driver.php’ file from the one on github, as per this:
http://ellislab.com/forums/viewthread/206124/
...but that just generates other errors, not to mention is disturbing to a newbie who does not want to touch the system files if at all possible.
This thread also seems to imply the need to be hacking the ‘pdo_driver.php’ system file:
http://stackoverflow.com/questions/11054618/codeigniter-pdo-database-driver-not-working
It seems odd to me that (someone thought that) a hack to a system file is needed to make PDO work in CI v.2.1.1, doesn’t it?
——————————————————————————————————————————————————————————
Another (ongoing) question I have is this:
Why are people complaining about CI’s implementation of PDO? Like e.g.:
http://ellislab.com/forums/viewthread/218455/
“PDO with only support for QUERY is pretty useless”
Can we indeed use prepare/Execute, or not? Do we really need to (for guaranteed safety against SQL injection)? If not, then why all the relentless fuss (on PHP forums) about PDO/bound parameters anyway (in terms of security)?
(I have not used PDO before, nor anything other than CI’s Active Record, so forgive me if I am asking what may supposed to be obvious.
There seems to be a lot of confusion about what is best security practice.. and how to follow it, with CI. Here’s some others that (for me anyway) just adds to the feeling of being unsure:
http://stackoverflow.com/questions/9765128/codeigniter-pdo-driver-uses-query-instead-of-prepare-isnt-this-less-secure
http://stackoverflow.com/questions/8743943/codeigniter-pdo-integration
http://stackoverflow.com/questions/9284274/codeigniter-using-pdo-instead-of-mysql
There are also MySQLi and PDO drivers. None of them use prepared statements because parameter-placeholder escaping is done by CI already. – Francis Avila”
...but in other threads I am not finding just now, people complain that in the end (even for CI’s “Query Bindings”) CI still relies on mysql_* to escape.. and that is inherently unsafe.
?
Thanks for any feedback, especially how to just get PDO working for my (first on localhost) CI app.