本文整理匯總了PHP中PDO::setCharset方法的典型用法代碼示例。如果您正苦於以下問題:PHP PDO::setCharset方法的具體用法?PHP PDO::setCharset怎麽用?PHP PDO::setCharset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PDO
的用法示例。
在下文中一共展示了PDO::setCharset方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: init
/**
* 初始化DB句柄
*
* @return void
* @throws WindDbException
*/
public function init()
{
try {
if ($this->_dbHandle !== null) {
return;
}
$driverName = $this->getDriverName();
$dbHandleClass = "WIND:db." . $driverName . ".Wind" . ucfirst($driverName) . "PdoAdapter";
$dbHandleClass = Wind::import($dbHandleClass);
$this->_dbHandle = new $dbHandleClass($this->_dsn, $this->_user, $this->_pwd, (array) $this->_attributes);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$this->_dbHandle->setCharset($this->_charset);
} catch (PDOException $e) {
$this->close();
throw new WindDbException('[db.WindConnection.init] ' . $e->getMessage());
}
}
示例2: init
/**
* 初始化DB句柄
*
* @return void
* @throws WindDbException
*/
public function init()
{
try {
if ($this->_dbHandle !== null) {
return;
}
$driverName = $this->getDriverName();
$dbHandleClass = "WIND:db." . $driverName . ".Wind" . ucfirst($driverName) . "PdoAdapter";
$dbHandleClass = Wind::import($dbHandleClass);
$this->_dbHandle = new $dbHandleClass($this->_dsn, $this->_user, $this->_pwd, (array) $this->_attributes);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->_dbHandle->setCharset($this->_charset);
if (WIND_DEBUG & 2) {
Wind::getApp()->getComponent('windLogger')->info("[db.WindConnection.init] Initialize db connection success. \r\n\tDSN:" . $this->_dsn . "\r\n\tUser:" . $this->_user . "\r\n\tCharset:" . $this->_charset . "\r\n\tTablePrefix:" . $this->_tablePrefix . "\r\n\tDriverName:" . $this->_driverName, 'db');
}
} catch (PDOException $e) {
$this->close();
throw new WindDbException($e->getMessage());
}
}