本文整理匯總了PHP中pdo::__construct方法的典型用法代碼示例。如果您正苦於以下問題:PHP pdo::__construct方法的具體用法?PHP pdo::__construct怎麽用?PHP pdo::__construct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pdo
的用法示例。
在下文中一共展示了pdo::__construct方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
/**
* @param array $config
*/
public function __construct($config)
{
$_alldbtype = array('mysql', 'pgsql', 'mssql', 'sybase', 'dblib');
$driver_options = array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_PERSISTENT => $config['persistent'], PDO::ATTR_CASE => PDO::CASE_LOWER, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC);
if (in_array($config['dbtype'], $_alldbtype)) {
$dsn = $config['dbtype'] . ':dbname=' . $config['dbname'] . ';host=' . $config['dbhost'] . ';charset=' . $config['charset'];
if (!empty($config['dbport'])) {
$dsn .= ';port=' . $config['dbport'];
}
$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
} elseif ($config['dbtype'] == 'oci') {
$dsn = 'oci:dbname=//' . $config['dbhost'] . ':' . $config['dbport'] . '/' . $config['dbname'] . ';charset=AL32UTF8';
$driver_options[PDO::ATTR_STRINGIFY_FETCHES] = true;
} elseif ($config['dbtype'] == 'sqlite') {
$dsn = 'sqlite:' . $config['dbname'];
} else {
trigger_error($config['dbtype'] . ' is not supported', 256);
}
$this->server = $config['dbhost'];
$this->dbtype = $config['dbtype'];
$this->dbname = $config['dbname'];
$this->user = $config['dbuname'];
try {
parent::__construct($dsn, $config['dbuname'], $config['dbpass'], $driver_options);
parent::exec("SET SESSION time_zone='" . NV_SITE_TIMEZONE_GMT_NAME . "'");
$this->connect = 1;
} catch (PDOException $e) {
trigger_error($e->getMessage());
}
}
示例2: __construct
public function __construct()
{
$this->dbtype = 'mysql';
$this->host = 'localhost';
$this->user = 'root';
$this->pass = '';
$this->database = 'mks';
$dns = $this->dbtype . ':dbname=' . $this->database . ";host=" . $this->host;
parent::__construct($dns, $this->user, $this->pass);
}
示例3:
function __construct()
{
parent::__construct(DB_TYPE . ":host=" . DB_HOST . ";dbname=" . DB, DB_USER, DB_PASS);
}