Welcome Guest, Not a member yet? Register   Sign In
Bug in PDO driver class?
#1

[eluser]musonic[/eluser]
I tried using the new PDO driver that is included with CI 2.1.0. It didn't go well. It was unable to create a connection. I think I tracked down the problem and fixed it, but I never like adding (or removing) anything from the core.
The problem seemed to be when instantiating a new PDO instance. On line 114 of pro_driver.php we have:
Code:
return new PDO($this->hostname, $this->username, $this->password, $this->options);
The problem is that
Code:
$this->hostname
is incorrect. In my case this is currently just localhost.
Currently it is set on line 81:
Code:
$this->hostname .= ";dbname=".$this->database;
The problem is that it is missing the first bit of the string that PDO needs. Immediately before line 81 I have added
Code:
$this->hostname = 'mysql:host='.$this->hostname;
This builds the correct string and I can now connect as expected. Of course the problem with this fix is that I've hardcoded mysql...
#2

[eluser]Unknown[/eluser]
I think that this is a better solution, edit the database config file in:

Code:
application/config/database.php

configure the hostname like this:

Code:
$db['default']['hostname'] = 'mysql:host=localhost';

It is working fine for me.

Maybe this is the expected way of working with it, the UserGuide is still outdated,
I think they are working on it.

Sorry for my poor english.
#3

[eluser]CroNiX[/eluser]
There has been a LOT of work on the PDO driver on github in the last month or so which will be in the next release. You can try the PDO drivers from there and see if it helps.




Theme © iAndrew 2016 - Forum software by © MyBB