Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how set charset parameter like ?charset=utf8 #227

Open
tablecell opened this issue Mar 12, 2017 · 1 comment
Open

how set charset parameter like ?charset=utf8 #227

tablecell opened this issue Mar 12, 2017 · 1 comment
Labels

Comments

@tablecell
Copy link

  • adapter://user:password@protocol+host:110//usr/db_file.db?mode=0644
  • adapter://user:password@host/database_name
  • adapter://user:password@host
  • adapter://user@host
  • adapter://host/database
  • adapter://host
  • adapter(dbsyntax)
  • adapter

found nothing config charset

@willemwollebrants
Copy link
Contributor

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants