/** * Connect to a database and log in as the specified user. * * @param string $dsn the data source name (see DB::parseDSN for syntax) * @param boolean $persistent (optional) whether the connection should * be persistent * @return mixed DB_OK on success, a DB error on failure * @access public */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('mysqli')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $conn = false; @ini_set('track_errors', true); if ($this->getOption('ssl') === true) { $init = mysqli_init(); mysqli_ssl_set($init, empty($dsninfo['key']) ? null : $dsninfo['key'], empty($dsninfo['cert']) ? null : $dsninfo['cert'], empty($dsninfo['ca']) ? null : $dsninfo['ca'], empty($dsninfo['capath']) ? null : $dsninfo['capath'], empty($dsninfo['cipher']) ? null : $dsninfo['cipher']); if ($conn = @mysqli_real_connect($init, $dsninfo['hostspec'], $dsninfo['username'], $dsninfo['password'], $dsninfo['database'], $dsninfo['port'], $dsninfo['socket'])) { $conn = $init; } } else { $conn = @mysqli_connect($dsninfo['hostspec'], $dsninfo['username'], $dsninfo['password'], $dsninfo['database'], $dsninfo['port'], $dsninfo['socket']); } @ini_restore('track_errors'); if (!$conn) { if (($err = @mysqli_connect_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } elseif (empty($php_errormsg)) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsninfo['database']) { $this->_db = $dsninfo['database']; } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('sybase') && !DB::assertExtension('sybase_ct')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $interface = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect'; $dsninfo['password'] = !empty($dsninfo['password']) ? $dsninfo['password'] : false; $dsninfo['charset'] = isset($dsninfo['charset']) ? $dsninfo['charset'] : false; $dsninfo['appname'] = isset($dsninfo['appname']) ? $dsninfo['appname'] : false; if ($interface && $dsninfo['username']) { $conn = @$connect_function($interface, $dsninfo['username'], $dsninfo['password'], $dsninfo['charset'], $dsninfo['appname']); } else { $conn = false; } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } if ($dsninfo['database']) { if (!@sybase_select_db($dsninfo['database'], $conn)) { return $this->raiseError(DB_ERROR_NODBSELECTED, null, null, null, @sybase_get_last_message()); } $this->_db = $dsninfo['database']; } $this->connection = $conn; return DB_OK; }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('interbase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] . ':' . $dsninfo['database'] : $dsninfo['database']; $connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect'; $params = array(); $params[] = $dbhost; $params[] = $dsninfo['username'] ? $dsninfo['username'] : null; $params[] = $dsninfo['password'] ? $dsninfo['password'] : null; $params[] = isset($dsninfo['charset']) ? $dsninfo['charset'] : null; $params[] = isset($dsninfo['buffers']) ? $dsninfo['buffers'] : null; $params[] = isset($dsninfo['dialect']) ? $dsninfo['dialect'] : null; $params[] = isset($dsninfo['role']) ? $dsninfo['role'] : null; $conn = @call_user_func_array($connect_function, $params); if (!$conn) { return $this->ibaseRaiseError(DB_ERROR_CONNECT_FAILED); } $this->connection = $conn; if ($this->dsn['dbsyntax'] == 'firebird') { $this->features['limit'] = 'alter'; } return DB_OK; }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('interbase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] . ':/' . $dsninfo['database'] : $dsninfo['database']; $connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect'; if ($dbhost && $user && $pw) { $conn = $connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = $connect_function($dbhost, $user); } elseif ($dbhost) { $conn = $connect_function($dbhost); } else { return $this->raiseError("no host, user or password"); } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('fbsql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $php_errormsg = ''; $connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect'; if ($dbhost && $dsninfo['username'] && $dsninfo['password']) { $conn = @$connect_function($dbhost, $dsninfo['username'], $dsninfo['password']); } elseif ($dbhost && $dsninfo['username']) { $conn = @$connect_function($dbhost, $dsninfo['username']); } elseif ($dbhost) { $conn = @$connect_function($dbhost); } else { $conn = false; } if (!$conn) { if (empty($php_errormsg)) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsninfo['database']) { if (!fbsql_select_db($dsninfo['database'], $conn)) { return $this->fbsqlRaiseError(); } } $this->connection = $conn; return DB_OK; }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('mssql') && !DB::assertExtension('sybase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect'; if ($dbhost && $user && $pw) { $conn = @$connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = @$connect_function($dbhost, $user); } else { $conn = @$connect_function($dbhost); } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, mssql_get_last_message()); } if ($dsninfo['database']) { if (!@mssql_select_db($dsninfo['database'], $conn)) { return $this->raiseError(DB_ERROR_NODBSELECTED, null, null, null, mssql_get_last_message()); } } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('sybase') && !DB::assertExtension('sybase_ct')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $interface = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect'; if ($interface && $dsninfo['username'] && $dsninfo['password']) { $conn = @$connect_function($interface, $dsninfo['username'], $dsninfo['password']); } elseif ($interface && $dsninfo['username']) { /* * Using false for pw as a workaround to avoid segfault. * See PEAR bug 631 */ $conn = @$connect_function($interface, $dsninfo['username'], false); } else { $conn = false; } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } if ($dsninfo['database']) { if (!@sybase_select_db($dsninfo['database'], $conn)) { return $this->raiseError(DB_ERROR_NODBSELECTED, null, null, null, @sybase_get_last_message()); } $this->_db = $dsninfo['database']; } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('odbc')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; if (!empty($dsninfo['dbsyntax'])) { $this->dbsyntax = $dsninfo['dbsyntax']; } switch ($this->dbsyntax) { case 'solid': $this->features = array('prepare' => true, 'pconnect' => true, 'transactions' => true); $default_dsn = 'localhost'; break; default: break; } $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $user = $dsninfo['username']; $pw = $dsninfo['password']; if ($this->provides('pconnect')) { $connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect'; } else { $connect_function = 'odbc_connect'; } $conn = @$connect_function($dbhost, $user, $pw); if (!is_resource($conn)) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $this->errorNative()); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('oci8')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $hostspec = $dsninfo['hostspec']; $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon'; if ($hostspec) { $conn = @$connect_function($user, $pw, $hostspec); } elseif ($user || $pw) { $conn = @$connect_function($user, $pw); } else { $conn = false; } if ($conn == false) { $error = OCIError(); $error = is_array($error) ? $error['message'] : null; return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $error); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $ssl (optional) whether the connection should * use the ssl method or not * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $ssl = false) { if (!DB::assertExtension('mysql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') { $dbhost = ':' . $dsninfo['socket']; } else { $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; if (!empty($dsninfo['port'])) { $dbhost .= ':' . $dsninfo['port']; } } $user = $dsninfo['username']; $pw = $dsninfo['password']; $ssl_mode = $ssl ? 'CLIENT_SSL' : NULL; @ini_set('track_errors', true); if ($dbhost && $user && $pw) { // Need to verify if arguments are okay $conn = @mysql_connect($dbhost, $user, $pw, $ssl_mode); } elseif ($dbhost && $user) { $conn = @mysql_connect($dbhost, $user, NULL, $ssl_mode); } elseif ($dbhost) { $conn = @mysql_connect($dbhost, NULL, NULL, $ssl_mode); } else { $conn = false; } @ini_restore('track_errors'); if (empty($conn)) { if (($err = @mysql_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } elseif (empty($php_errormsg)) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsninfo['database']) { if (!@mysql_select_db($dsninfo['database'], $conn)) { switch (mysql_errno($conn)) { case 1049: return $this->raiseError(DB_ERROR_NOSUCHDB, null, null, null, mysql_error($conn)); break; case 1044: return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null, null, mysql_error($conn)); break; default: return $this->raiseError(DB_ERROR, null, null, null, mysql_error($conn)); break; } } // fix to allow calls to different databases in the same script $this->_db = $dsninfo['database']; } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('mysql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') { $dbhost = ':' . $dsninfo['socket']; } else { $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; if (!empty($dsninfo['port'])) { $dbhost .= ':' . $dsninfo['port']; } } $user = $dsninfo['username']; $pw = $dsninfo['password']; $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect'; if ($dbhost && $user && $pw) { $conn = @$connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = @$connect_function($dbhost, $user); } elseif ($dbhost) { $conn = @$connect_function($dbhost); } else { $conn = false; } if (empty($conn)) { if (($err = @mysql_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } elseif (empty($php_errormsg)) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsninfo['database']) { if (!@mysql_select_db($dsninfo['database'], $conn)) { switch (mysql_errno($conn)) { case 1049: return $this->raiseError(DB_ERROR_NOSUCHDB, null, null, null, mysql_error($conn)); break; case 1044: return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null, null, mysql_error($conn)); break; default: return $this->raiseError(DB_ERROR, null, null, null, mysql_error($conn)); break; } } // fix to allow calls to different databases in the same script $this->_db = $dsninfo['database']; } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure. */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('pgsql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $protocol = $dsninfo['protocol'] ? $dsninfo['protocol'] : 'tcp'; $connstr = ''; if ($protocol == 'tcp') { if ($dsninfo['hostspec']) { $connstr .= 'host=' . $dsninfo['hostspec']; } if ($dsninfo['port']) { $connstr .= ' port=' . $dsninfo['port']; } } elseif ($protocol == 'unix') { // Allow for pg socket in non-standard locations. if ($dsninfo['socket']) { $connstr .= 'host=' . $dsninfo['socket']; } if ($dsninfo['port']) { $connstr .= ' port=' . $dsninfo['port']; } } if ($dsninfo['database']) { $connstr .= ' dbname=\'' . addslashes($dsninfo['database']) . '\''; } if ($dsninfo['username']) { $connstr .= ' user=\'' . addslashes($dsninfo['username']) . '\''; } if ($dsninfo['password']) { $connstr .= ' password=\'' . addslashes($dsninfo['password']) . '\''; } if (!empty($dsninfo['options'])) { $connstr .= ' options=' . $dsninfo['options']; } if (!empty($dsninfo['tty'])) { $connstr .= ' tty=' . $dsninfo['tty']; } $connect_function = $persistent ? 'pg_pconnect' : 'pg_connect'; $ini = ini_get('track_errors'); if ($ini) { $conn = @$connect_function($connstr); } else { ini_set('track_errors', 1); $conn = @$connect_function($connstr); ini_set('track_errors', $ini); } if ($conn == false) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, strip_tags($php_errormsg)); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure. */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('pgsql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $protocol = $dsninfo['protocol'] ? $dsninfo['protocol'] : 'tcp'; $connstr = ''; if ($protocol == 'tcp') { if ($dsninfo['hostspec']) { $connstr .= 'host=' . $dsninfo['hostspec']; } if ($dsninfo['port']) { $connstr .= ' port=' . $dsninfo['port']; } } elseif ($protocol == 'unix') { // Allow for pg socket in non-standard locations. if ($dsninfo['socket']) { $connstr .= 'host=' . $dsninfo['socket']; } } if ($dsninfo['database']) { $connstr .= ' dbname=\'' . addslashes($dsninfo['database']) . '\''; } if ($dsninfo['username']) { $connstr .= ' user=\'' . addslashes($dsninfo['username']) . '\''; } if ($dsninfo['password']) { $connstr .= ' password=\'' . addslashes($dsninfo['password']) . '\''; } if (isset($dsninfo['options'])) { $connstr .= ' options=' . $dsninfo['options']; } if (isset($dsninfo['tty'])) { $connstr .= ' tty=' . $dsninfo['tty']; } $connect_function = $persistent ? 'pg_pconnect' : 'pg_connect'; // catch error ob_start(); $conn = $connect_function($connstr); $error = ob_get_contents(); ob_end_clean(); if ($conn == false) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, strip_tags($error)); } $this->connection = $conn; return DB_OK; }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('dbase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; ob_start(); $conn = dbase_open($dsninfo['database'], 0); $error = ob_get_contents(); ob_end_clean(); if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, strip_tags($error)); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('pgsql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $host = $dsninfo['hostspec']; $protocol = isset($dsninfo['protocol']) ? $dsninfo['protocol'] : ''; $connstr = ''; if ($host !== false && $protocol != 'unix') { if (($pos = strpos($host, ':')) !== false) { $dbhost = substr($host, 0, $pos); $port = substr($host, $pos + 1); } else { $dbhost = $host; $port = '5432'; } $connstr = 'host=' . $dbhost . ' port=' . $port; } if (isset($dsninfo['database'])) { $connstr .= ' dbname=' . $dsninfo['database']; } if (isset($dsninfo['username'])) { $connstr .= ' user='******'username']; } if (isset($dsninfo['password'])) { $connstr .= ' password='******'password']; } if (!empty($dsninfo['options'])) { $connstr .= ' options=' . $dsninfo['options']; } if (!empty($dsninfo['tty'])) { $connstr .= ' tty=' . $dsninfo['tty']; } $connect_function = $persistent ? 'pg_pconnect' : 'pg_connect'; // catch error ob_start(); $conn = $connect_function($connstr); $error = ob_get_contents(); ob_end_clean(); if ($conn == false) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, strip_tags($error)); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure */ function connect(&$dsninfo, $persistent = false) { if (!DB::assertExtension('informix')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $dbhost = $dsninfo['hostspec'] ? '@' . $dsninfo['hostspec'] : ''; $dbname = $dsninfo['database'] ? $dsninfo['database'] . $dbhost : ''; $user = $dsninfo['username'] ? $dsninfo['username'] : ''; $pw = $dsninfo['password'] ? $dsninfo['password'] : ''; $connect_function = $persistent ? 'ifx_pconnect' : 'ifx_connect'; $this->connection = @$connect_function($dbname, $user, $pw); if (!is_resource($this->connection)) { return $this->ifxraiseError(DB_ERROR_CONNECT_FAILED); } return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('mysql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $user = $dsninfo['username']; $pw = $dsninfo['password']; $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect'; @ini_set('track_errors', true); if ($dbhost && $user && $pw) { $conn = @$connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = @$connect_function($dbhost, $user); } elseif ($dbhost) { $conn = @$connect_function($dbhost); } else { $conn = false; } @ini_restore('track_errors'); if (empty($conn)) { if (($err = @mysql_error()) != '') { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $err); } elseif (empty($php_errormsg)) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } else { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg); } } if ($dsninfo['database']) { // fix to allow calls to different databases in the same script if (empty($GLOBALS['_DB_mysql_changed_database'])) { $this->_changed_db = false; if (!@mysql_select_db($dsninfo['database'], $conn)) { return $this->raiseError(DB_ERROR_NODBSELECTED, null, null, null, mysql_error($conn)); } } else { $GLOBALS['_DB_mysql_changed_database'] = true; $this->_changed_db = $dsninfo['database']; } } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('odbc')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; if ($dsninfo['dbsyntax']) { $this->dbsyntax = $dsninfo['dbsyntax']; } switch ($this->dbsyntax) { case 'solid': $this->features = array('prepare' => true, 'pconnect' => true, 'transactions' => true); break; case 'navision': // the Navision driver doesn't support fetch row by number $this->features['limit'] = false; } /* * This is hear for backwards compatibility. * Should have been using 'database' all along, but used hostspec. */ if ($dsninfo['database']) { $odbcdsn = $dsninfo['database']; } elseif ($dsninfo['hostspec']) { $odbcdsn = $dsninfo['hostspec']; } else { $odbcdsn = 'localhost'; } if ($this->provides('pconnect')) { $connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect'; } else { $connect_function = 'odbc_connect'; } if (empty($dsninfo['cursor'])) { $conn = @$connect_function($odbcdsn, $dsninfo['username'], $dsninfo['password']); } else { $conn = @$connect_function($odbcdsn, $dsninfo['username'], $dsninfo['password'], $dsninfo['cursor']); } if (!is_resource($conn)) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $this->errorNative()); } $this->connection = $conn; return DB_OK; }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('dbase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $ini = ini_get('track_errors'); if ($ini) { $conn = @dbase_open($dsninfo['database'], 0); } else { ini_set('track_errors', 1); $conn = @dbase_open($dsninfo['database'], 0); ini_set('track_errors', $ini); } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, strip_tags($php_errormsg)); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('sybase') && !DB::assertExtension('sybase_ct')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $interface = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect'; if ($interface && $user && $pw) { $conn = $connect_function($interface, $user, $pw); } else { $conn = FALSE; } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database represented by a file. * * @param $dsn the data source name; the file is taken as * database; "sqlite://root:@host/test.db?mode=0644" * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('sqlite')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; if ($dsninfo['database']) { if (!file_exists($dsninfo['database'])) { if (!touch($dsninfo['database'])) { return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); } if (!isset($dsninfo['mode']) || !is_numeric($dsninfo['mode'])) { $mode = 0644; } else { $mode = octdec($dsninfo['mode']); } if (!chmod($dsninfo['database'], $mode)) { return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); } if (!file_exists($dsninfo['database'])) { return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); } } if (!is_file($dsninfo['database'])) { return $this->sqliteRaiseError(DB_ERROR_INVALID); } if (!is_readable($dsninfo['database'])) { return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); } } else { return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); } $connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open'; if (!($conn = @$connect_function($dsninfo['database']))) { return $this->sqliteRaiseError(DB_ERROR_NODBSELECTED); } $this->connection = $conn; return DB_OK; }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('interbase')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] . ':/' . $dsninfo['database'] : $dsninfo['database']; $connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect'; $params = array(); $params[] = $dbhost; $params[] = !empty($user) ? $user : null; $params[] = !empty($pw) ? $pw : null; $params[] = isset($dsninfo['charset']) ? $dsninfo['charset'] : null; $params[] = isset($dsninfo['buffers']) ? $dsninfo['buffers'] : null; $params[] = isset($dsninfo['dialect']) ? $dsninfo['dialect'] : null; $params[] = isset($dsninfo['role']) ? $dsninfo['role'] : null; /* if ($dbhost && $user && $pw) { $conn = $connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = $connect_function($dbhost, $user); } elseif ($dbhost) { $conn = $connect_function($dbhost); } else { return $this->raiseError("no host, user or password"); } */ $conn = @call_user_func_array($connect_function, $params); if (!$conn) { return $this->ibaseRaiseError(DB_ERROR_CONNECT_FAILED); } $this->connection = $conn; return DB_OK; }
function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('msql')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect'; if ($dbhost && $dsninfo['username'] && $dsninfo['password']) { $conn = $connect_function($dbhost, $dsninfo['username'], $dsninfo['password']); } elseif ($dbhost && $dsninfo['username']) { $conn = $connect_function($dbhost, $dsninfo['username']); } else { $conn = $connect_function($dbhost); } if (!$conn) { $this->raiseError(DB_ERROR_CONNECT_FAILED); } if (!@msql_select_db($dsninfo['database'], $conn)) { return $this->raiseError(DB_ERROR_NODBSELECTED); } $this->connection = $conn; return DB_OK; }
/** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * * @return int DB_OK on success, a DB error code on failure */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension("oci8")) return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $hostspec = $dsninfo['hostspec']; $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon'; if ($hostspec) { $conn = @$connect_function($user,$pw,$hostspec); } elseif ($user || $pw) { $conn = @$connect_function($user,$pw); } else { $conn = false; } if ($conn == false) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } $this->connection = $conn; return DB_OK; }
/** * Connect and bind to LDAP server with either anonymous or authenticated bind depending on dsn info * * @param array $dsninfo dsn info as passed by DB::connect() * @param boolean $persistent kept for interface compatibility * @return DB_OK if successfully connected. A DB error code is returned on failure. */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('ldap')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; $host = $dsninfo['hostspec']; $this->base = $dsninfo['database']; if ($host) { $conn = ldap_connect($host); } else { return $this->raiseError("unknown host {$host}"); } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } if ($user && $pw) { $bind = ldap_bind($conn, "{$user}," . $this->base, $pw); } else { $bind = ldap_bind($conn); } if (!$bind) { return $this->raiseError(DB_ERROR_BIND_FAILED); } $this->connection = $conn; return DB_OK; }
/** * Connect and bind to LDAP server with either anonymous or authenticated bind depending on dsn info * * @param array $dsninfo dsn info as passed by DB::connect() * @param boolean $persistent kept for interface compatibility * @return DB_OK if successfully connected. A DB error code is returned on failure. */ function connect($dsninfo, $persistent = false) { if (!DB::assertExtension('ldap')) { return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); } $this->dsn = $dsninfo; $user = $dsninfo['username']; $pw = $dsninfo['password']; if (($colon_pos = strpos($dsninfo['hostspec'], ':')) !== false) { $host = substr($dsninfo['hostspec'], 0, $colon_pos); $port = substr($dsninfo['hostspec'], $colon_pos + 1); } else { $host = $dsninfo['hostspec']; $port = null; } $this->base = $dsninfo['database']; $this->d_base = $this->base; if (empty($host)) { return $this->raiseError("no host specified {$host}"); } // else ... if (isset($port)) { $conn = ldap_connect($host, $port); } else { $conn = ldap_connect($host); } if (!$conn) { return $this->raiseError(DB_ERROR_CONNECT_FAILED); } if ($user && $pw) { $bind = @ldap_bind($conn, $user, $pw); } else { $bind = @ldap_bind($conn); } if (!$bind) { return $this->raiseError(DB_ERROR_BIND_FAILED); } $this->connection = $conn; return DB_OK; }