Exemplo n.º 1
1
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'database', 'file');
     $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
     $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
     if (isset($config['resource']) && $config['resource'] instanceof SQLite3) {
         $this->connection = $config['resource'];
     } else {
         try {
             $this->connection = new SQLite3($config['database']);
         } catch (Exception $e) {
             throw new DibiDriverException($e->getMessage(), $e->getCode());
         }
     }
     $this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset'];
     $this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset'];
     if (strcasecmp($this->dbcharset, $this->charset) === 0) {
         $this->dbcharset = $this->charset = NULL;
     }
     // enable foreign keys support (defaultly disabled; if disabled then foreign key constraints are not enforced)
     $version = SQLite3::version();
     if ($version['versionNumber'] >= '3006019') {
         $this->query("PRAGMA foreign_keys = ON");
     }
 }
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'database', 'file');
     $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
     $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
     $errorMsg = '';
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } elseif (empty($config['persistent'])) {
         $this->connection = @sqlite_open($config['database'], 0666, $errorMsg);
         // intentionally @
     } else {
         $this->connection = @sqlite_popen($config['database'], 0666, $errorMsg);
         // intentionally @
     }
     if (!$this->connection) {
         throw new DibiDriverException($errorMsg);
     }
     $this->buffered = empty($config['unbuffered']);
     $this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset'];
     $this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset'];
     if (strcasecmp($this->dbcharset, $this->charset) === 0) {
         $this->dbcharset = $this->charset = NULL;
     }
 }
Exemplo n.º 3
0
Arquivo: mysqli.php Projeto: vlki/dibi
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'options');
     DibiConnection::alias($config, 'database');
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         // default values
         if (!isset($config['username'])) {
             $config['username'] = ini_get('mysqli.default_user');
         }
         if (!isset($config['password'])) {
             $config['password'] = ini_get('mysqli.default_pw');
         }
         if (!isset($config['socket'])) {
             $config['socket'] = ini_get('mysqli.default_socket');
         }
         if (!isset($config['port'])) {
             $config['port'] = NULL;
         }
         if (!isset($config['host'])) {
             $host = ini_get('mysqli.default_host');
             if ($host) {
                 $config['host'] = $host;
                 $config['port'] = ini_get('mysqli.default_port');
             } else {
                 $config['host'] = NULL;
                 $config['port'] = NULL;
             }
         }
         $this->connection = mysqli_init();
         @mysqli_real_connect($this->connection, $config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket'], $config['options']);
         // intentionally @
         if ($errno = mysqli_connect_errno()) {
             throw new DibiDriverException(mysqli_connect_error(), $errno);
         }
     }
     if (isset($config['charset'])) {
         $ok = FALSE;
         if (version_compare(PHP_VERSION, '5.1.5', '>=')) {
             // affects the character set used by mysql_real_escape_string() (was added in MySQL 5.0.7 and PHP 5.0.5, fixed in PHP 5.1.5)
             $ok = @mysqli_set_charset($this->connection, $config['charset']);
             // intentionally @
         }
         if (!$ok) {
             $ok = @mysqli_query($this->connection, "SET NAMES '{$config['charset']}'");
             // intentionally @
             if (!$ok) {
                 throw new DibiDriverException(mysqli_error($this->connection), mysqli_errno($this->connection));
             }
         }
     }
     if (isset($config['sqlmode'])) {
         if (!@mysqli_query($this->connection, "SET sql_mode='{$config['sqlmode']}'")) {
             // intentionally @
             throw new DibiDriverException(mysqli_error($this->connection), mysqli_errno($this->connection));
         }
     }
     $this->buffered = empty($config['unbuffered']);
 }
Exemplo n.º 4
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'username', 'user');
     DibiConnection::alias($config, 'password', 'pass');
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         // default values
         if (!isset($config['username'])) {
             $config['username'] = ini_get('odbc.default_user');
         }
         if (!isset($config['password'])) {
             $config['password'] = ini_get('odbc.default_pw');
         }
         if (!isset($config['dsn'])) {
             $config['dsn'] = ini_get('odbc.default_db');
         }
         if (empty($config['persistent'])) {
             $this->connection = @odbc_connect($config['dsn'], $config['username'], $config['password']);
             // intentionally @
         } else {
             $this->connection = @odbc_pconnect($config['dsn'], $config['username'], $config['password']);
             // intentionally @
         }
     }
     if (!is_resource($this->connection)) {
         throw new DibiDriverException(odbc_errormsg() . ' ' . odbc_error());
     }
 }
Exemplo n.º 5
0
 /**
  * Connects to a database.
  *
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'username', 'user');
     DibiConnection::alias($config, 'password', 'pass');
     DibiConnection::alias($config, 'database', 'db');
     DibiConnection::alias($config, 'charset');
     $this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']);
     // intentionally @
     if (!$this->connection) {
         $err = oci_error();
         throw new DibiDriverException($err['message'], $err['code']);
     }
 }
Exemplo n.º 6
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'options|UID', 'username');
     DibiConnection::alias($config, 'options|PWD', 'password');
     DibiConnection::alias($config, 'options|Database', 'database');
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         $this->connection = sqlsrv_connect($config['host'], (array) $config['options']);
     }
     if (!is_resource($this->connection)) {
         $info = sqlsrv_errors();
         throw new DibiDriverException($info[0]['message'], $info[0]['code']);
     }
 }
Exemplo n.º 7
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'charset');
     $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
     $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         $this->connection = @oci_new_connect($config['username'], $config['password'], $config['database'], $config['charset']);
         // intentionally @
     }
     if (!$this->connection) {
         $err = oci_error();
         throw new DibiDriverException($err['message'], $err['code']);
     }
 }
Exemplo n.º 8
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'host', 'hostname');
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } elseif (isset($config['options'])) {
         $this->connection = sqlsrv_connect($config['host'], $config['options']);
     } else {
         $this->connection = sqlsrv_connect($config['host']);
     }
     if (!is_resource($this->connection)) {
         $info = sqlsrv_errors();
         throw new DibiDriverException($info[0]['message'], $info[0]['code']);
     }
     $this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset'];
 }
Exemplo n.º 9
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         if (!isset($config['charset'])) {
             $config['charset'] = 'utf8';
         }
         if (isset($config['string'])) {
             $string = $config['string'];
         } else {
             $string = '';
             DibiConnection::alias($config, 'user', 'username');
             DibiConnection::alias($config, 'dbname', 'database');
             foreach (array('host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service') as $key) {
                 if (isset($config[$key])) {
                     $string .= $key . '=' . $config[$key] . ' ';
                 }
             }
         }
         DibiDriverException::tryError();
         if (empty($config['persistent'])) {
             $this->connection = pg_connect($string, PGSQL_CONNECT_FORCE_NEW);
         } else {
             $this->connection = pg_pconnect($string, PGSQL_CONNECT_FORCE_NEW);
         }
         if (DibiDriverException::catchError($msg)) {
             throw new DibiDriverException($msg, 0);
         }
     }
     if (!is_resource($this->connection)) {
         throw new DibiDriverException('Connecting error.');
     }
     if (isset($config['charset'])) {
         DibiDriverException::tryError();
         pg_set_client_encoding($this->connection, $config['charset']);
         if (DibiDriverException::catchError($msg)) {
             throw new DibiDriverException($msg, 0);
         }
     }
     if (isset($config['schema'])) {
         $this->query('SET search_path TO "' . $config['schema'] . '"');
     }
     $this->escMethod = version_compare(PHP_VERSION, '5.2.0', '>=');
 }
Exemplo n.º 10
0
 /**
  * Connects to a database.
  *
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'database', 'file');
     $this->fmtDate = isset($config['format:date']) ? $config['format:date'] : 'U';
     $this->fmtDateTime = isset($config['format:datetime']) ? $config['format:datetime'] : 'U';
     $errorMsg = '';
     if (empty($config['persistent'])) {
         $this->connection = @sqlite_open($config['database'], 0666, $errorMsg);
         // intentionally @
     } else {
         $this->connection = @sqlite_popen($config['database'], 0666, $errorMsg);
         // intentionally @
     }
     if (!$this->connection) {
         throw new DibiDriverException($errorMsg);
     }
     $this->buffered = empty($config['unbuffered']);
 }
Exemplo n.º 11
0
Arquivo: pdo.php Projeto: vrana/dibi
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'dsn');
     DibiConnection::alias($config, 'resource', 'pdo');
     DibiConnection::alias($config, 'options');
     if ($config['resource'] instanceof PDO) {
         $this->connection = $config['resource'];
     } else {
         try {
             $this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
         } catch (PDOException $e) {
             throw new DibiDriverException($e->getMessage(), $e->getCode());
         }
     }
     if (!$this->connection) {
         throw new DibiDriverException('Connecting error.');
     }
 }
Exemplo n.º 12
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     $foo =& $config['dsn'];
     $foo =& $config['options'];
     DibiConnection::alias($config, 'resource', 'pdo');
     if ($config['resource'] instanceof PDO) {
         $this->connection = $config['resource'];
     } else {
         try {
             $this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
         } catch (PDOException $e) {
             if ($e->getMessage() === 'could not find driver') {
                 throw new DibiNotSupportedException("PHP extension for PDO is not loaded.");
             }
             throw new DibiDriverException($e->getMessage(), $e->getCode());
         }
     }
     $this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
 }
Exemplo n.º 13
0
 /**
  * Connects to a database.
  *
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'username', 'user');
     DibiConnection::alias($config, 'password', 'pass');
     DibiConnection::alias($config, 'host', 'hostname');
     if (empty($config['persistent'])) {
         $this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE);
         // intentionally @
     } else {
         $this->connection = @mssql_pconnect($config['host'], $config['username'], $config['password']);
         // intentionally @
     }
     if (!is_resource($this->connection)) {
         throw new DibiDriverException("Can't connect to DB.");
     }
     if (isset($config['database']) && !@mssql_select_db($config['database'], $this->connection)) {
         // intentionally @
         throw new DibiDriverException("Can't select DB '{$config['database']}'.");
     }
 }
Exemplo n.º 14
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'database', 'db');
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         // default values
         if (!isset($config['username'])) {
             $config['username'] = ini_get('ibase.default_password');
         }
         if (!isset($config['password'])) {
             $config['password'] = ini_get('ibase.default_user');
         }
         if (!isset($config['database'])) {
             $config['database'] = ini_get('ibase.default_db');
         }
         if (!isset($config['charset'])) {
             $config['charset'] = ini_get('ibase.default_charset');
         }
         if (!isset($config['buffers'])) {
             $config['buffers'] = 0;
         }
         DibiDriverException::tryError();
         if (empty($config['persistent'])) {
             $this->connection = ibase_connect($config['database'], $config['username'], $config['password'], $config['charset'], $config['buffers']);
             // intentionally @
         } else {
             $this->connection = ibase_pconnect($config['database'], $config['username'], $config['password'], $config['charset'], $config['buffers']);
             // intentionally @
         }
         if (DibiDriverException::catchError($msg)) {
             throw new DibiDriverException($msg, ibase_errcode());
         }
         if (!is_resource($this->connection)) {
             throw new DibiDriverException(ibase_errmsg(), ibase_errcode());
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Connects to a database.
  * @return void
  * @throws DibiException
  */
 public function connect(array &$config)
 {
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         // default values
         DibiConnection::alias($config, 'flags', 'options');
         if (!isset($config['charset'])) {
             $config['charset'] = 'utf8';
         }
         if (!isset($config['username'])) {
             $config['username'] = ini_get('mysql.default_user');
         }
         if (!isset($config['password'])) {
             $config['password'] = ini_get('mysql.default_password');
         }
         if (!isset($config['host'])) {
             $host = ini_get('mysql.default_host');
             if ($host) {
                 $config['host'] = $host;
                 $config['port'] = ini_get('mysql.default_port');
             } else {
                 if (!isset($config['socket'])) {
                     $config['socket'] = ini_get('mysql.default_socket');
                 }
                 $config['host'] = NULL;
             }
         }
         if (empty($config['socket'])) {
             $host = $config['host'] . (empty($config['port']) ? '' : ':' . $config['port']);
         } else {
             $host = ':' . $config['socket'];
         }
         if (empty($config['persistent'])) {
             $this->connection = @mysql_connect($host, $config['username'], $config['password'], TRUE, $config['flags']);
             // intentionally @
         } else {
             $this->connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['flags']);
             // intentionally @
         }
     }
     if (!is_resource($this->connection)) {
         throw new DibiDriverException(mysql_error(), mysql_errno());
     }
     if (isset($config['charset'])) {
         $ok = FALSE;
         if (function_exists('mysql_set_charset')) {
             // affects the character set used by mysql_real_escape_string() (was added in MySQL 5.0.7 and PHP 5.2.3)
             $ok = @mysql_set_charset($config['charset'], $this->connection);
             // intentionally @
         }
         if (!$ok) {
             $this->query("SET NAMES '{$config['charset']}'");
         }
     }
     if (isset($config['database'])) {
         if (!@mysql_select_db($config['database'], $this->connection)) {
             // intentionally @
             throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection));
         }
     }
     if (isset($config['sqlmode'])) {
         $this->query("SET sql_mode='{$config['sqlmode']}'");
     }
     $this->query("SET time_zone='" . date('P') . "'");
     $this->buffered = empty($config['unbuffered']);
 }
Exemplo n.º 16
0
 public function connect(array &$config)
 {
     DibiConnection::alias($config, 'username', 'user');
     DibiConnection::alias($config, 'password', 'pass');
     DibiConnection::alias($config, 'host', 'hostname');
     DibiConnection::alias($config, 'options');
     if (!isset($config['username'])) {
         $config['username'] = ini_get('mysql.default_user');
     }
     if (!isset($config['password'])) {
         $config['password'] = ini_get('mysql.default_password');
     }
     if (!isset($config['host'])) {
         $host = ini_get('mysql.default_host');
         if ($host) {
             $config['host'] = $host;
             $config['port'] = ini_get('mysql.default_port');
         } else {
             if (!isset($config['socket'])) {
                 $config['socket'] = ini_get('mysql.default_socket');
             }
             $config['host'] = NULL;
         }
     }
     if (empty($config['socket'])) {
         $host = $config['host'] . (empty($config['port']) ? '' : ':' . $config['port']);
     } else {
         $host = ':' . $config['socket'];
     }
     if (empty($config['persistent'])) {
         $this->connection = @mysql_connect($host, $config['username'], $config['password'], TRUE, $config['options']);
     } else {
         $this->connection = @mysql_pconnect($host, $config['username'], $config['password'], $config['options']);
     }
     if (!is_resource($this->connection)) {
         throw new DibiDriverException(mysql_error(), mysql_errno());
     }
     if (isset($config['charset'])) {
         $ok = FALSE;
         if (function_exists('mysql_set_charset')) {
             $ok = @mysql_set_charset($config['charset'], $this->connection);
         }
         if (!$ok) {
             $ok = @mysql_query("SET NAMES '{$config['charset']}'", $this->connection);
             if (!$ok) {
                 throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection));
             }
         }
     }
     if (isset($config['database'])) {
         if (!@mysql_select_db($config['database'], $this->connection)) {
             throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection));
         }
     }
     if (isset($config['sqlmode'])) {
         if (!@mysql_query("SET sql_mode='{$config['sqlmode']}'", $this->connection)) {
             throw new DibiDriverException(mysql_error($this->connection), mysql_errno($this->connection));
         }
     }
     $this->buffered = empty($config['unbuffered']);
 }
Exemplo n.º 17
0
NotSupportedException("PHP extension 'sqlite3' is not loaded.");}}function
connect(array&$config){DibiConnection::alias($config,'database','file');$this->fmtDate=isset($config['formatDate'])?$config['formatDate']:'U';$this->fmtDateTime=isset($config['formatDateTime'])?$config['formatDateTime']:'U';if(isset($config['resource'])&&$config['resource']instanceof
SQLite3){$this->connection=$config['resource'];}else
try{$this->connection=new
SQLite3($config['database']);}catch(Exception$e){throw
new
DibiDriverException($e->getMessage(),$e->getCode());}$this->dbcharset=empty($config['dbcharset'])?'UTF-8':$config['dbcharset'];$this->charset=empty($config['charset'])?'UTF-8':$config['charset'];if(strcasecmp($this->dbcharset,$this->charset)===0){$this->dbcharset=$this->charset=NULL;}$version=SQLite3::version();if($version['versionNumber']>='3006019'){$this->query("PRAGMA foreign_keys = ON");}}function