コネクションストリングにオプションで書けば出来んじゃないかと思ったのですが、UTF-8使う場合はqueryメソッドでSET NAMESを書くみたいです。。。
<?php
require_once('DB.php');
class DatabaseConnection {
var $_handle = null;
function &get () {
static $db;
if (!isset($db)) {
$db = new DatabaseConnection();
}
return $db;
}
function DatabaseConnection () {
$phptype = $GLOBALS['DSN']['phptype'];
$hostspec = $GLOBALS['DSN']['hostspec'];
$database = $GLOBALS['DSN']['database'];
$username = $GLOBALS['DSN']['username'];
$password = $GLOBALS['DSN']['password'];
$dsn = "$phptype://$username:$password@$hostspec/$database";
$this->_handle = DB::Connect($dsn);
if (DB::isError($this->_handle)) {
die($this->_handle->getMessage());
}
$this->_handle->setFetchMode(DB_FETCHMODE_ASSOC);
$this->_handle->query("SET NAMES 'utf8'");
}
function handle () {
return $this->_handle;
}
}
いまだに、PEAR::DB使ってるのにびっくりしますが | |д・) ソォーッ…
