spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

how set charset parameter like ?charset=utf8 #227

Open tablecell opened 7 years ago

tablecell commented 7 years ago
willemwollebrants commented 7 years ago

Here's how I do it (mysql):

$config = new \Spot\Config();
$config->addConnection('fromString', 'mysql://user:password@localhost/database?charset=utf8mb4');

//check the collation to see if it worked
echo $cfg->connection('fromString')->query("SELECT COLLATION('foo') AS charset;")->fetchColumn();
//outputs "utf8mb4_general_ci"

To be perfectly honest, that's not actually how I do it. I prefer the array-syntax:

$config = new \Spot\Config();
$config->addConnection('fromArray', [
    'dbname' => 'database',
    'user' => 'user',
    'password' => 'password',
    'host' => 'localhost',
    'driver' => 'pdo_mysql',
    'charset' => 'utf8mb4'
]);

//check the collation to see if it worked
echo $cfg->connection('fromArray')->query("SELECT COLLATION('foo') AS charset;")->fetchColumn();
//outputs "utf8mb4_general_ci"