Closed ghost closed 14 years ago
This is actually slightly more tricky that it looks. If I use the code you supplied, it creates the assumption that if a username and password are supplied, the database being used must be MySQL. This isn't necessarily the case - for example the MS SQL driver also requires these options: http://www.php.net/manual/en/ref.pdo-dblib.php . Although Idiorm probably doesn't even support MS SQL (I haven't tested it), I'm a bit reluctant to build in this assumption.
My current idea is to keep the API fairly low level here, and add a driver_options
setting, which would pass a raw array of settings through to the PDO constructor if supplied. So the full initialisation for MySQL would look like this:
ORM::configure('mysql:host=localhost;dbname=my_database');
ORM::configure('username', 'database_user');
ORM::configure('password', 'top_secret');
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
Do you have any thoughts on this solution?
Add 'driver_options' setting to allow driver-specific connection options to be passed through to the PDO constructor. Closed by 6547b15aee997fb0db43c7fc0b1f33110993e215
Sorry about my late reply. The 'driver_options' config setting sounds great. Looking forward to an updated version of the class. Btw, are there any other changes/fixes planned?
Hi,
This setting was added and documented in SHA: 6547b15aee997fb0db43c7fc0b1f33110993e215 . There are a few other fixes in this release. Any suggestions for other changes for the next version would be appreciated!
To make Idiorm UTF-8 compatible, add:
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
to the setup_db function in the main class.
Code: