Example #1
0
 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"));
 }
Example #2
0
 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);
 }
Example #3
0
 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);
 }
Example #4
0
 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);
     }
 }
Example #5
0
 /**
  * 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();
 }
 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);
 }
Example #7
0
 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;
 }
 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';");
 }
Example #9
0
File: Db.php Project: ukrcms/ukrcms
 /**
  * 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;
 }
Example #10
0
 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;
 }
Example #11
0
 function __construct($user, $pass, $host, $dbname)
 {
     $engine = 'mysql';
     $host = 'localhost';
     $dns = $engine . ':dbname=' . $dbname . ";host=" . $host;
     parent::__construct($dns, $user, $pass);
 }
Example #12
0
 private function conecta()
 {
     if (!$this->conectado) {
         parent::__construct(DB_TYPE . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
         $this->conectado = true;
     }
 }
 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);
 }
Example #14
0
 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);
 }
Example #15
0
 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));
 }
Example #16
0
 /**
  * Creates a new PDO instance
  *
  * @param string $type				Simple string such as 'mysql' or a PDO DNS string
  * @param string $dbname
  * @param string $host
  * @param string $user
  * @param string $pass
  * @param string $port
  * @param array $opts	PDO specific driver options
  */
 public function __construct($type, $dbname = '', $host = '', $user = '', $pass = '', $port = '', array $opts = array())
 {
     if (empty($dbname) && empty($host)) {
         $dns = $type;
         // Get the driver that is to be used
         $splitDns = explode(':', $dns);
         $driver = $splitDns[0];
     } else {
         if ($type == 'mysql' || $type == 'mysqli') {
             $driver = 'mysql';
             $dns = sprintf('mysql:host=%1$s;dbname=%2$s', $host, $dbname);
             if (trim($port)) {
                 $dns .= ';port=' . $port;
             }
         } else {
             if ($type == 'pgsql') {
                 $driver = 'pgsql';
                 $port = trim($port) ? $port : 5432;
                 $dns = sprintf('pgsql:host=%1$s port=%2$s dbname=%3$s user=%3$s password=%4$s', $host, $port, $dbname, $user, $pass);
             }
         }
     }
     if (!in_array($driver, PDO::getAvailableDrivers())) {
         throw new SQL_InvalidDriver('PDO driver "' . $driver . '" is not available, ensure it is installed', 20);
     }
     try {
         $opts = array_merge($opts, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
         if ($driver == 'mysql') {
             $opts[PDO::MYSQL_ATTR_USE_BUFFERED_QUERY] = true;
         }
         parent::__construct($dns, $user, $pass, $opts);
     } catch (PDOexception $e) {
         throw new SQL_UnableToConnect($e->getMessage(), 21);
     }
 }
Example #17
0
 /**
  * possible sqlserver values are mysql, sybase, mssql
  */
 public function __construct($host, $user, $pass, $dbname = null, $sqlserver = "mysql")
 {
     try {
         if (strtolower($sqlserver) == "mysql") {
             $dsn = "mysql:host={$host}";
             if ($dbname) {
                 $this->dbname = $dbname;
                 $dsn = "mysql:host={$host};dbname={$dbname}";
             }
             parent::__construct($dsn, $user, $pass);
         } else {
             if (strtolower($sqlserver) == "sqlite") {
                 $dsn = "sqlite:{$dbname}";
                 parent::__construct($dsn);
             } else {
                 die("Unknown DSN. Please set config.php");
             }
         }
         Logger::getLogger("AuieoATS")->info("dsn is {$dsn}");
         $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->setStopOnError();
         $this->fetchmode = PDO::FETCH_ASSOC;
     } catch (PDOException $e) {
         die($e);
     }
 }
Example #18
0
 public function __construct()
 {
     parent::__construct("mysql:host=localhost;dbname=busticket;", "root", "");
     $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     // always disable emulated prepared statement when using the MySQL driver
     $this->setAttribute(\PDO::ATTR_EMULATE_PREPARES, TRUE);
 }
Example #19
0
 /**
  * 构造函数
  *
  * @access public
  * @param string $dsn 数据源
  * @param string $user 连接帐户
  * @param string $password 连接密码
  * @param array $options 选项
  */
 public function __construct($dsn, $user, $password, $options = array())
 {
     parent::__construct($dsn, $user, $password, $options);
     $this->setAttribute(PDO::ATTR_TIMEOUT, 30);
     $this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
     $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Driver_Db_Pdostatement', array($this)));
 }
Example #20
0
 function __construct()
 {
     if (DB_TYPE == "pgsql") {
         try {
             //PostgreSQL
             parent::__construct(DB_TYPE . ":host=" . DB_HOST . ";port=" . DB_PORT . ";dbname=" . DB_NAME . ";user="******";password="******"<script>alert('" . $e->getMessage() . "')</script>";
         }
     } else {
         if (DB_TYPE == "mysql") {
             try {
                 // 		MySQL
                 parent::__construct(DB_TYPE . ":host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS);
             } catch (PDOException $e) {
                 echo "<script>alert('" . $e->getMessage() . "')</script>";
             }
         } else {
             try {
                 // 		DB2
                 parent::__construct(DB_TYPE . ":DRIVER={" . DB_DRIVER . "};DATABASE=" . DB_NAME . ";" . "HOSTNAME=" . DB_HOST . ";PORT=" . DB_PORT . ";PROTOCOL=" . DB_PROTOCOL . ";", DB_USER, DB_PASS);
             } catch (PDOException $e) {
                 echo "<script>alert('" . $e->getMessage() . "')</script>";
             }
         }
     }
 }
Example #21
0
 public function __construct()
 {
     set_exception_handler(array(__CLASS__, 'exception_handler'));
     $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => $this->persistent);
     parent::__construct('mysql:host=' . $this->host . ';dbname=' . $this->database . ';charset=' . $this->charset, $this->user, $this->password, $options);
     restore_exception_handler();
 }
Example #22
0
 public function connect()
 {
     if (!$this->isConnected) {
         parent::__construct($this->dsn, $this->user, $this->password, $this->options);
         $this->isConnected = true;
     }
 }
Example #23
0
 public function __construct($dsn, $username = null, $password = null, $driver_options = null)
 {
     parent::__construct($dsn, $username, $password, $driver_options);
     $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('StormPDOStatement', array($this)));
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
 }
Example #24
0
 function PDOdb($db_type)
 {
     $args = func_get_args();
     $this->type = $db_type;
     switch ($db_type) {
         case self::ACCESS:
             $args[0] = self::ODBC;
             call_user_func_array(array($this, 'odbc_access'), $args);
             break;
         case self::MSSQL:
             $args[0] = self::ODBC;
             call_user_func_array(array($this, 'odbc_mssql'), $args);
             break;
         case self::MYSQL:
             call_user_func_array(array($this, 'mysql'), $args);
             break;
         case self::PGSQL:
             call_user_func_array(array($this, 'pgsql'), $args);
             break;
         default:
     }
     // Instanciate PDO and connect to DB or die
     try {
         parent::__construct($this->dsn, $this->uid, $this->pwd);
         $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         echo sprintf("Message : %s<br/><br/>", $e->getMessage());
         die;
     }
 }
Example #25
0
 /**
  * Constructs a new PDO intance.
  *
  * @param string $dsn Connection string.
  * @param string $user User to login to database with.
  * @param string $password Password to login to database with.
  * @param Array $driverOptions Various driver option.
  * @param string $prefix Table prefix to use instead of the default one.
  */
 public function __construct($dsn, $user = null, $password = null, $driverOptions = array(), $prefix = null)
 {
     if (strpos($dsn, "sqlite:") === 0) {
         $this->sqliteFilePath = substr($dsn, strlen("sqlite:"));
     }
     if (strpos($dsn, "mysql:") === 0) {
         $newDsn = array();
         $parts = explode(';', substr($dsn, strlen("mysql:")));
         foreach ($parts as $part) {
             $part = explode('=', $part);
             if ($part[0] == 'username') {
                 $user = trim($part[1]);
             } else {
                 if ($part[0] == 'password') {
                     $password = trim($part[1]);
                 } else {
                     $newDsn[] = implode('=', $part);
                 }
             }
         }
         $dsn = "mysql:" . implode(';', $newDsn);
     }
     parent::__construct($dsn, $user, $password, $driverOptions);
     $this->tablePrefix = $prefix;
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $this->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
 }
 public function __construct()
 {
     DBParameters::construct();
     parent::__construct('mysql:host=' . DBParameters::Hostname() . ';dbname=' . DBParameters::DBname(), DBParameters::Username(), DBParameters::Password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
     // parent::setFetchMode(PDO::FETCH_OBJ);
     $this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
 }
Example #27
0
 function __construct()
 {
     $config = \Yaf\Application::app()->getConfig()->database['mysql'];
     $dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['dbname']}";
     parent::__construct($dsn, $config['user'], $config['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES'utf8';"));
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
Example #28
0
 /**
  *
  * @param string $host 数据库地址
  * @param int $port 端口
  * @param string $username 帐号
  * @param string $passwd 密码
  * @param string $database 数据库
  * @param string $charset 编码,默认为utf8,也建议使用utf8
  */
 public function __construct($host, $port, $username, $passwd, $database, $charset = "utf8")
 {
     $dsn = 'mysql:dbname=' . $database . ';host=' . $host . ';port=' . $port;
     $this->_dsn = $dsn;
     $options = array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'set names ' . $charset, \PDO::ATTR_CASE => \PDO::CASE_LOWER, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_TIMEOUT => 30, \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC);
     parent::__construct($dsn, $username, $passwd, $options);
 }
Example #29
0
 public function __construct($dsn, $user, $password)
 {
     parent::__construct($dsn, $user, $password);
     $this->query("SET NAMES ´utf8´");
     $this->query("SET CHARACTER SET utf8");
     logger("INFO", "Database Class Initialized");
 }
Example #30
0
 public function __construct()
 {
     // load the config object
     $config = Load::library('Config');
     // get the connection name based off the enviroment
     $connection = $config->getEnvironment();
     // load the connection details
     $details = $config->get('connections.' . $connection);
     try {
         // instantiate the PDO object
         $this->dbh = parent::__construct($details[0], $details[1], $details[2]);
     } catch (PDOException $e) {
         if ($config->isDev()) {
             // throw the original exception
             throw new Exception('PDO exception caught: ' . $e->getMessage());
         } else {
             // throw the generic DB exception
             throw new Exception('Database connection error');
         }
     }
     // set the PDO error mode to exception
     parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // return the DB handle
     return $this->dbh;
 }