LoginSignup
7
7

More than 5 years have passed since last update.

PhalconのDbAdapterにchareset=utf8を渡す(MySQL)

Posted at

PHP 5.3.7以上では、PDOで、以下のような形で文字コード設定を行えます。

$con = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'dbuser', 'password');

PhalconのDbAdapterで同じことをやりたい場合、以下のように書きます。

$db = new Phalcon\Db\Adapter\Pdo\Mysql([
    'dsn'      => 'mysql:host=localhost;dbname=test;charset=utf8',
    'username' => 'dbuser',
    'password' => 'password',
]);

又は

$db = new Phalcon\Db\Adapter\Pdo\Mysql([
    'host'     => 'localhost',
    'username' => 'dbuser',
    'password' => 'password',
    'dbname'   => 'test',
    'charset'  => 'utf8',
]);

内部では、hostやcharsetをdsnとして組み立てて、PDOのコンストラクタに渡してます。したがって、どちらの書き方をしても結果は同じです。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7