本文整理汇总了PHP中PDO::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::__construct方法的具体用法?PHP PDO::__construct怎么用?PHP PDO::__construct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($dsn, $username = null, $password = null, array $driver_options = null)
{
parent::__construct($dsn, $username, $password, $driver_options);
$this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, array("PdoStatement"));
}
示例2: __construct
public function __construct()
{
global $phpbb_root_path;
$database = $phpbb_root_path . 'store/messenger.db';
parent::__construct('sqlite:' . $database);
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
示例3: connect
function connect()
{
parent::__construct('mysql:host=' . $this->DB_HOST . ';dbname=' . $this->DB_NAME, $this->DB_USER, $this->DB_PASS);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// always disable emulated prepared statement when using the MySQL driver
$this->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
示例4: __construct
public function __construct($dsn, $username, $password, $options = [])
{
$post_query = null;
// Let's grab the DB engine
if (strpos($dsn, ':') !== false) {
$this->dbengine = explode(':', $dsn)[0];
}
// If no charset is specified, default to UTF-8
switch ($this->dbengine) {
case 'mysql':
if (strpos($dsn, ';charset=') === false) {
$dsn .= ';charset=utf8';
}
break;
case 'pgsql':
$post_query = 'SET NAMES UNICODE';
break;
}
// Let's call the parent constructor now
parent::__construct($dsn, $username, $password, $options);
// Let's turn off emulated prepares
$this->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
if (!empty($post_query)) {
$this->query($post_query);
}
}
示例5: array
/**
* Creates a data source instance to represent a connection to the database.
* The first argument can either be a string DSN or an array which contains
* the construction arguments.
*
* @param mixed $dsn String DSN or array of arguments (dsn, username, password)
* @param string $username
* @param string $password
* @param array $driver_options
*/
function __construct($dsn, $username = '', $password = '', $driver_options = array())
{
if (is_array($dsn)) {
$args = $dsn;
if (isset($args[0])) {
$dsn = $args[0];
}
if (isset($args[1])) {
$username = $args[1];
}
if (isset($args[2])) {
$password = $args[2];
}
if (isset($args[3])) {
$driver_options = $args[3];
}
}
try {
parent::__construct($dsn, $username, $password, $driver_options);
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $exception) {
throw new DataSourceCouldNotConnectException($exception->getMessage(), get_defined_vars());
}
$this->cachePrefix = self::CACHE_PREFIX . $dsn . '::*::';
$this->provider = $this->instantiateProvider();
}
示例6: __construct
public function __construct(array $config)
{
$dsn = sprintf('%s:host=%s;dbname=%s', $config['dbtype'], $config['dbhost'], $config['dbname']);
$username = isset($config['username']) ? $config['username'] : '';
$password = isset($config['password']) ? $config['password'] : '';
parent::__construct($dsn, $username, $password);
}
示例7: __construct
public function __construct($database)
{
if (is_array($database)) {
$db_config = $database;
} else {
$db_config = EE::is_set('_config', 'databases', $database) ? EE::get('_config', 'databases', $database) : false;
}
if (!$db_config) {
trigger_error('No database config of ' . $database . ' found', E_USER_WARNING);
}
if (!isset($db_config['dsn'])) {
trigger_error('No database dsn config of ' . $database . ' found', E_USER_WARNING);
}
$extension = substr($db_config['dsn'], 0, strpos($db_config['dsn'], ':'));
if (!in_array($extension, PDO::getAvailableDrivers())) {
trigger_error('PDO extension of ' . $extension . ' could not be found', E_USER_WARNING);
}
$instance = null;
$username = isset($db_config['username']) ? $db_config['username'] : null;
$password = isset($db_config['password']) ? $db_config['password'] : null;
$params = isset($db_config['params']) ? $db_config['params'] : null;
try {
$instance = parent::__construct($db_config['dsn'], $username, $password, $params);
} catch (PDOException $e) {
trigger_error('Could not connect to database ' . $database . ': ' . $e->getMessage(), E_USER_ERROR);
}
return $instance;
}
示例8: __construct
public function __construct($connConfigName = 'default')
{
if (!isset(self::$arrConnConfig[$connConfigName])) {
throw new Exception("JPDO Exception : connConfigName '{$connConfigName}' does not exist!");
}
$connConfig = self::$arrConnConfig[$connConfigName];
if (!isset($connConfig['dsn'])) {
throw new Exception("JPDO Exception : in connConfig '{$connConfigName}', 'dsn' should has been set!");
}
if (!isset($connConfig['user'])) {
throw new Exception("JPDO Exception : in connConfig '{$connConfigName}', 'user' should has been set!");
}
if (!isset($connConfig['password'])) {
throw new Exception("JPDO Exception : in connConfig '{$connConfigName}', 'password' should has been set!");
}
$attr = array();
if (isset($connConfig['persistent_connection']) && $connConfig['persistent_connection'] == 'Y') {
$attr[PDO::ATTR_PERSISTENT] = true;
$attr[PDO::ATTR_AUTOCOMMIT] = true;
}
try {
@parent::__construct($connConfig['dsn'], $connConfig['user'], $connConfig['password'], $attr);
} catch (PDOException $e) {
print "DB Error: " . $e->getMessage() . "<br />";
}
$this->query("SET NAMES 'utf8';");
}
示例9: connect
/**
* Connect to database
*
* @return $this
*/
public function connect()
{
parent::__construct($this->dsn, $this->username, $this->password, $this->options);
$this->execute('SET NAMES UTF8');
$this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $this;
}
示例10: __construct
public function __construct($dsn, $username = null, $passwd = null, $options = null)
{
parent::__construct($dsn, $username, $passwd, $options);
$this->listeners = new \ArrayObject();
$this->muteListeners = false;
$this->transactionName = null;
}
示例11:
function __construct($user, $pass, $host, $dbname)
{
$engine = 'mysql';
$host = 'localhost';
$dns = $engine . ':dbname=' . $dbname . ";host=" . $host;
parent::__construct($dns, $user, $pass);
}
示例12: conecta
private function conecta()
{
if (!$this->conectado) {
parent::__construct(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
$this->conectado = true;
}
}
示例13: __construct
public function __construct($dsn = null, $username = null, $password = null, array $driver_options = null)
{
// Get the System DB Config
global $databaseConfig;
// Make the config easier to work with
$conf = (object) $databaseConfig;
// fix for sqlite dbs
$type = strtolower(str_replace('Database', '', $conf->type));
if ($type == 'sqlitepdo') {
$type = 'sqlite';
}
// DSN
if (!$dsn) {
$dsn = $type . ':' . 'host=' . $conf->server . ';' . 'dbname=' . $conf->database;
}
// Authentication
if (!$username) {
$username = $conf->username;
}
if (!$password) {
$password = $conf->password;
}
// Connect
parent::__construct($dsn, $username, $password, $driver_options);
}
示例14: __construct
public function __construct($host, $dbName, $user, $pass, ErrorHandler $errorHandler, $dbType = 'mysql')
{
$this->errorHandler = $errorHandler;
parent::__construct($dbType . ':host=' . $host . ';dbname=' . $dbName, $user, $pass);
// Throw an exception in case of an error
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
示例15: __construct
public function __construct()
{
if (self::$dsn === null) {
throw new DatabaseException('Booya\\DatabaseException: dsn not configured.');
}
parent::__construct(self::$dsn, self::$username, self::$password, array(self::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", self::ATTR_EMULATE_PREPARES => false, self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION));
}