本文整理汇总了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());
}
}