/** * 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; }
protected function _connect() { //try { $this->_config = App::$_registry["db"]; //pr($this->_config);exit; // if connected return if ($this->_connection) { return; } if (isset($this->_config['port'])) { $port = (int) $this->_config['port']; } else { $port = null; } $this->_connection = mysqli_init(); $_isConnected = @mysqli_real_connect($this->_connection, $this->_config['host'], $this->_config['username'], $this->_config['password'], $this->_config['dbname'], $port, null, MYSQLI_CLIENT_FOUND_ROWS); if ($_isConnected === false || mysqli_connect_errno()) { $this->closeConnection(); //throw new \Exception(mysqli_connect_error()); show_error('DB Error', mysqli_connect_error()); } //} /* catch (\Exception $e) { echo $e->getTraceAsString(); } */ }
/** * 连接数据库 * @param array $array 数据库连接配置 * $array=array( * 'dbmysql_server', * 'dbmysql_username', * 'dbmysql_password', * 'dbmysql_name', * 'dbmysql_pre', * 'dbmysql_port', * 'persistent' * 'engine') * @return bool */ public function Open($array) { $db = mysqli_init(); if ($array[6] == true) { $array[0] = 'p:' . $array[0]; } //mysqli_options($db,MYSQLI_READ_DEFAULT_GROUP,"max_allowed_packet=50M"); if (@mysqli_real_connect($db, $array[0], $array[1], $array[2], $array[3], $array[5])) { $myver = mysqli_get_server_info($db); $this->version = substr($myver, 0, strpos($myver, "-")); if (version_compare($this->version, '5.5.3') >= 0) { $u = "utf8mb4"; } else { $u = "utf8"; } if (mysqli_set_charset($db, $u) == false) { mysqli_set_charset($db, "utf8"); } $this->db = $db; $this->dbname = $array[3]; $this->dbpre = $array[4]; $this->dbengine = $array[7]; return true; } return false; }
/** * @param object $link * @param array $options */ public function __construct($link = false, $options = array()) { foreach ($options as $key => $value) { $this->{$key} = $value; } if ($link) { $this->link = $link; } else { if (!empty($options)) { if (isset($this->host)) { $this->hostname = $this->host; } if (isset($this->dbname)) { $this->database = $this->dbname; } //$this->link = @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); $this->link = mysqli_init(); mysqli_options($this->link, MYSQLI_OPT_CONNECT_TIMEOUT, 1); if (@mysqli_real_connect($this->link, $this->hostname, $this->username, $this->password, $this->database)) { $names = "SET NAMES '" . $this->charset . "';"; mysqli_query($this->link, $names); $charset = "SET CHARSET '" . $this->charset . "';"; mysqli_query($this->link, $charset); } else { $this->link = false; } } } }
/** * connects to the database server * * @uses $GLOBALS['cfg']['Server'] * @uses PMA_auth_fails() * @uses PMA_DBI_postConnect() * @uses MYSQLI_CLIENT_COMPRESS * @uses MYSQLI_OPT_LOCAL_INFILE * @uses strtolower() * @uses mysqli_init() * @uses mysqli_options() * @uses mysqli_real_connect() * @uses defined() * @param string $user mysql user name * @param string $password mysql user password * @param boolean $is_controluser * @return mixed false on error or a mysqli object on success */ function PMA_DBI_connect($user, $password, $is_controluser = false) { $server_port = empty($GLOBALS['cfg']['Server']['port']) ? false : (int) $GLOBALS['cfg']['Server']['port']; if (strtolower($GLOBALS['cfg']['Server']['connect_type']) == 'tcp') { $GLOBALS['cfg']['Server']['socket'] = ''; } // NULL enables connection to the default socket $server_socket = empty($GLOBALS['cfg']['Server']['socket']) ? null : $GLOBALS['cfg']['Server']['socket']; $link = mysqli_init(); mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, true); $client_flags = 0; /* Optionally compress connection */ if ($GLOBALS['cfg']['Server']['compress'] && defined('MYSQLI_CLIENT_COMPRESS')) { $client_flags |= MYSQLI_CLIENT_COMPRESS; } /* Optionally enable SSL */ if ($GLOBALS['cfg']['Server']['ssl'] && defined('MYSQLI_CLIENT_SSL')) { $client_flags |= MYSQLI_CLIENT_SSL; } $return_value = mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, $password, false, $server_port, $server_socket, $client_flags); // Retry with empty password if we're allowed to if ($return_value == false && isset($cfg['Server']['nopassword']) && $cfg['Server']['nopassword'] && !$is_controluser) { $return_value = mysqli_real_connect($link, $GLOBALS['cfg']['Server']['host'], $user, '', false, $server_port, $server_socket, $client_flags); } if ($return_value == false) { if ($is_controluser) { trigger_error($GLOBALS['strControluserFailed'], E_USER_WARNING); return false; } PMA_auth_fails(); } // end if PMA_DBI_postConnect($link, $is_controluser); return $link; }
function _connect($argHostname = NULL, $argUsername = NULL, $argPassword = NULL, $argDatabasename = NULL, $persist = false) { if (!extension_loaded("mysqli")) { return null; } $this->_connectionID = @mysqli_init(); if (is_null($this->_connectionID)) { // mysqli_init only fails if insufficient memory if ($this->debug) { ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg()); } return false; } /* I suggest a simple fix which would enable adodb and mysqli driver to read connection options from the standard mysql configuration file /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com> */ foreach ($this->optionFlags as $arr) { mysqli_options($this->_connectionID, $arr[0], $arr[1]); } #if (!empty($this->port)) $argHostname .= ":".$this->port; $ok = mysqli_real_connect($this->_connectionID, $argHostname, $argUsername, $argPassword, $argDatabasename, $this->port, $this->socket, $this->clientFlags); if ($ok) { if ($argDatabasename) { return $this->SelectDB($argDatabasename); } return true; } else { if ($this->debug) { ADOConnection::outp("Could't connect : " . $this->ErrorMsg()); } return false; } }
function db_Connect($host = CMW_DB_HOST, $login = CMW_DB_LOGIN, $password = CMW_DB_PASSWORD, $name = CMW_DB_NAME, $port = _INI_MYSQLI_DEFAULT_PORT, $socket = _INI_MYSQLI_DEFAULT_SOCKET) { // Safely call this multiple times, only the first time has any effect // if (!db_IsConnected()) { global $db; $db = mysqli_init(); //mysqli_options($db, ...); if (defined('CMW_DB_PORT')) { $port = CMW_DB_PORT; } if (defined('CMW_DB_SOCKET')) { $socket = CMW_DB_SOCKET; } $flags = null; // Connect to the database // mysqli_real_connect($db, $host, $login, $password, $name, $port, $socket, $flags); // http://php.net/manual/en/mysqli.quickstart.connections.php if ($db->connect_errno) { db_Log("Failed to connect: (" . $db->connect_errno . ") " . $db->connect_error); } // Set character set to utf8mb4 mode (default is utf8mb3 (utf8). mb4 is required for Emoji) mysqli_set_charset($db, 'utf8mb4'); // More info: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through } }
function _connect($argHostname = NULL, $argUsername = NULL, $argPassword = NULL, $argDatabasename = NULL, $persist = false) { if (!extension_loaded("mysqli")) { return null; } $this->_connectionID = @mysqli_init(); if (is_null($this->_connectionID)) { // mysqli_init only fails if insufficient memory if ($this->debug) { ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg()); } return false; } // Set connection options // Not implemented now // mysqli_options($this->_connection,,); if (mysqli_real_connect($this->_connectionID, $argHostname, $argUsername, $argPassword, $argDatabasename, $this->port, $this->socket, $this->clientFlags)) { if ($argDatabasename) { return $this->SelectDB($argDatabasename); } return true; } else { if ($this->debug) { ADOConnection::outp("Could't connect : " . $this->ErrorMsg()); } return false; } }
/** * 连接数据库 * * @param array $config * @return string 返回连接的id */ public function doConnect(array &$config) { try { if (empty($persistent)) { $resource = \mysqli_init(); \mysqli_options($resource, \MYSQLI_OPT_CONNECT_TIMEOUT, 3); if (isset($this->config['option']) && is_array($this->config['option'])) { foreach ($this->config['option'] as $k => $v) { \mysqli_options($resource, $k, $v); } } \mysqli_real_connect($resource, $config['hostname'], $config['username'], $config['password'], $config['database'], $config['port'], null, \MYSQLI_CLIENT_COMPRESS); } else { $resource = new \mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['port']); } # 设置语言 $resource->set_charset($this->config['charset']); return $resource; } catch (Exception $e) { if (2 === $e->getCode() && preg_match('#(Unknown database|Access denied for user)#i', $e->getMessage(), $m)) { # 指定的库不存在,直接返回 $lastError = strtolower($m[1]) === 'unknown database' ? __('The mysql database does not exist') : __('The mysql database account or password error'); } else { $lastError = $e->getMessage(); } $lastErrorCode = $e->getCode(); } throw new Exception($lastError, $lastErrorCode); }
/** * Create connection with Db */ private function _connect() { $this->_connection = mysqli_init(); $_isConnected = @mysqli_real_connect($this->_connection, DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_PORT, null, MYSQLI_CLIENT_FOUND_ROWS); if ($_isConnected === false || mysqli_connect_errno()) { $this->closeConnection(); } }
/** */ function connect() { $this->db_connect_id = mysqli_init(); if (!$this->db_connect_id) { $this->_connect_error = 'cannot_connect_to_server'; $this->db_connect_id = null; return false; } foreach ((array) $this->INI_OPTS as $ini_name => $ini_val) { ini_set($ini_name, $ini_val); } if (!$this->ON_BEFORE_CONNECT) { $this->ON_BEFORE_CONNECT[] = function () { return $this->_on_before_connect_default(); }; } foreach ((array) $this->ON_BEFORE_CONNECT as $func) { if (is_callable($func)) { $func($this); } } if ($this->params['socket']) { $connect_host = $this->params['socket']; } else { $connect_port = $this->params['port'] && $this->params['port'] != $this->DEF_PORT ? $this->params['port'] : ''; $connect_host = ($this->params['persist'] ? 'p:' : '') . $this->params['host'] . ($connect_port ? ':' . $connect_port : ''); } mysqli_options($this->db_connect_id, MYSQLI_OPT_CONNECT_TIMEOUT, $this->CONNECT_TIMEOUT); $is_connected = mysqli_real_connect($this->db_connect_id, $this->params['host'], $this->params['user'], $this->params['pswd'], '', $this->params['port'], $this->params['socket'], $this->params['ssl'] ? MYSQLI_CLIENT_SSL : 0); if (!$is_connected) { $this->_connect_error = 'cannot_connect_to_server'; return false; } else { foreach ((array) $this->SQL_AFTER_CONNECT as $sql) { $this->query($sql); } } if ($this->params['name'] != '') { $dbselect = $this->select_db($this->params['name']); // Try to create database, if not exists and if allowed if (!$dbselect && $this->params['allow_auto_create_db'] && preg_match('/^[a-z0-9][a-z0-9_]+[a-z0-9]$/i', $this->params['name'])) { $res = $this->query('CREATE DATABASE IF NOT EXISTS ' . $this->params['name']); if ($res) { $dbselect = $this->select_db($this->params['name']); } } if (!$dbselect) { $this->_connect_error = 'cannot_select_db'; } foreach ((array) $this->ON_AFTER_CONNECT as $func) { if (is_callable($func)) { $func($this, $dbselect); } } return $dbselect; } }
public function connect() { if ($this->isConnected()) { return true; } @mysqli_real_connect($this->link, $this->route['host'], $this->route['username'], $this->route['password'], $this->route['dbname'], $this->route['port'], $this->route['socket']); $this->throwErrors(); $this->connected = true; }
public static function connect() { MySQLConnection::$db_connection = mysqli_init(); $connected = @mysqli_real_connect(MySQLConnection::$db_connection, MySQLConfiguration::host, MySQLConfiguration::username, MySQLConfiguration::password, MySQLConfiguration::database, MySQLConfiguration::port, MySQLConfiguration::socket, MYSQLI_CLIENT_COMPRESS); if (!$connected) { //Output error details Error::halt(503, 'service unavailable', 'Temporarily unable to process request. Failed to establish a connection with MySQL. Please retry.'); } }
/** * {@inheritDoc} */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { if (!function_exists('mysqli_connect')) { $this->connect_error = 'mysqli_connect function does not exist, is mysqli extension installed?'; return $this->sql_error(''); } // Mysqli extension supports persistent connection since PHP 5.3.0 $this->persistency = version_compare(PHP_VERSION, '5.3.0', '>=') ? $persistency : false; $this->user = $sqluser; // If persistent connection, set dbhost to localhost when empty and prepend it with 'p:' prefix $this->server = $this->persistency ? 'p:' . ($sqlserver ? $sqlserver : 'localhost') : $sqlserver; $this->dbname = $database; $port = !$port ? null : $port; // If port is set and it is not numeric, most likely mysqli socket is set. // Try to map it to the $socket parameter. $socket = null; if ($port) { if (is_numeric($port)) { $port = (int) $port; } else { $socket = $port; $port = null; } } $this->db_connect_id = mysqli_init(); if (!@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS)) { $this->db_connect_id = ''; } if ($this->db_connect_id && $this->dbname != '') { @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'"); // enforce strict mode on databases that support it if (version_compare($this->sql_server_info(true), '5.0.2', '>=')) { $result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode'); if ($result !== null) { $row = @mysqli_fetch_assoc($result); $modes = array_map('trim', explode(',', $row['sql_mode'])); } else { $modes = array(); } @mysqli_free_result($result); // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES if (!in_array('TRADITIONAL', $modes)) { if (!in_array('STRICT_ALL_TABLES', $modes)) { $modes[] = 'STRICT_ALL_TABLES'; } if (!in_array('STRICT_TRANS_TABLES', $modes)) { $modes[] = 'STRICT_TRANS_TABLES'; } } $mode = implode(',', $modes); @mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'"); } return $this->db_connect_id; } return $this->sql_error(''); }
private function createConnection($conf) { $handle = mysqli_init(); $ret = mysqli_real_connect($handle, $conf['ip'], $conf['user'], $conf['pass'], $this->dbname, $conf['port']); if (!$ret) { mysqli_close($handle); throw new \Exception('db.ConnectError ' . mysqli_error($handle)); } mysqli_set_charset($handle, $conf['charset']); return $handle; }
public function __construct($host = '127.0.0.1', $port = 9306, $debug = FALSE) { $this->sphinxql = mysqli_init(); if (!$this->sphinxql) { $this->error('MySQLi not initialed'); } if (!@mysqli_real_connect($this->sphinxql, $host, NULL, NULL, NULL, $port, NULL)) { $this->error('Can\'t connect to SphinxQL: ' . mysqli_connect_errno() . ' ' . mysqli_connect_error()); } $this->opts = $this->default_opts; $this->debug = (bool) $debug; }
function mysql_connect($hostname = null, $username = null, $password = null, $new = false, $flags = 0) { if ($new !== false) { trigger_error('Argument $new is no longer supported in PHP > 7', E_USER_WARNING); } if (null === $hostname) { $hostname = ini_get('mysqli.default_host') ?: null; } if (null === $username) { $username = ini_get('mysqli.default_user') ?: null; } if (null === $password) { $password = ini_get('mysqli.default_pw') ?: null; } $hash = sha1($hostname . $username . $flags); /* persistent connections start with p: */ if ($hostname[1] != ':' && isset(\Dshafik\MySQL::$connections[$hash])) { \Dshafik\MySQL::$last_connection = \Dshafik\MySQL::$connections[$hash]['conn']; \Dshafik\MySQL::$connections[$hash]['refcount'] += 1; return \Dshafik\MySQL::$connections[$hash]['conn']; } /* No flags, means we can use mysqli_connect() */ if ($flags === 0) { $conn = mysqli_connect($hostname, $username, $password); if (!$conn instanceof mysqli) { return false; } \Dshafik\MySQL::$last_connection = $conn; $conn->hash = $hash; \Dshafik\MySQL::$connections[$hash] = ['refcount' => 1, 'conn' => $conn]; return $conn; } /* Flags means we need to use mysqli_real_connect() instead, and handle exceptions */ try { \Dshafik\MySQL::$last_connection = $conn = mysqli_init(); mysqli_real_connect($conn, $hostname, $username, $password, '', null, '', $flags); // @codeCoverageIgnoreStart // PHPUnit turns the warning from mysqli_real_connect into an exception, so this never runs if ($conn === false) { return false; } // @codeCoverageIgnoreEnd $conn->hash = $hash; \Dshafik\MySQL::$connections[$hash] = ['refcount' => 1, 'conn' => $conn]; return $conn; } catch (\Throwable $e) { trigger_error($e->getMessage(), E_USER_WARNING); // @codeCoverageIgnoreStart // PHPUnit turns the warning into an exception, so this never runs return false; // @codeCoverageIgnoreEnd } }
/** * Helper function for connecting to the database server * * @param mysqli $link connection link * @param string $host mysql hostname * @param string $user mysql user name * @param string $password mysql user password * @param string $dbname database name * @param int $server_port server port * @param string $server_socket server socket * @param int $client_flags client flags of connection * @param bool $persistent whether to use persistent connection * * @return bool */ private function _realConnect($link, $host, $user, $password, $dbname, $server_port, $server_socket, $client_flags = null, $persistent = false) { global $cfg; // mysqli persistent connections if ($cfg['PersistentConnections'] || $persistent) { $host = 'p:' . $host; } if ($client_flags === null) { return @mysqli_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket); } else { return @mysqli_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket, $client_flags); } }
/** * Connect to the database * * @param string $server the server where the database is hosted * @param string $username username to access database * @param string $password password to access database * @param string $database the name of the database to connect to * @return boolean whether a connection was successful */ public function Connect($server = 'localhost', $username = '', $password = '', $database = '') { $this->_con = mysqli_init(); if ($ret = @mysqli_real_connect($this->_con, $server, $username, $password)) { $this->config = array('username' => $username, 'password' => $password, 'server' => $server); if ($database != "") { $connected = $this->SwitchDatabase($database); } $this->isConnected = $connected; } else { $this->CatchError($this->_langError[ERROR_CONNECTING] . ' in ' . __FILE__ . ' on line ' . __LINE__); } return $ret; }
public function connect() { $this->_conn = mysqli_init(); if (!$this->_conn) { throw new DB_Exception('mysqli_init fail!'); return false; } if (!mysqli_real_connect($this->_conn, HOST, USER, PASSWD, DBNAME, PORT, NULL, MYSQLI_CLIENT_FOUND_ROWS)) { throw new DB_Exception('connect to db fail:' . HOST . ":" . PORT . " " . USER . ":" . PASSWD . " " . DBNAME); return false; } $sql = "SET NAMES utf8"; $this->update($sql); return true; }
/** * Helper function for connecting to the database server * * @param mysqli $link connection link * @param string $host mysql hostname * @param string $user mysql user name * @param string $password mysql user password * @param string $dbname database name * @param int $server_port server port * @param string $server_socket server socket * @param int $client_flags client flags of connection * @param bool $persistent whether to use peristent connection * * @return bool */ function PMA_DBI_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket, $client_flags = null, $persistent = false) { global $cfg; // mysqli persistent connections only on PHP 5.3+ if (PMA_PHP_INT_VERSION >= 50300) { if ($cfg['PersistentConnections'] || $persistent) { $host = 'p:' . $host; } } if ($client_flags === null) { return @mysqli_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket); } else { return @mysqli_real_connect($link, $host, $user, $password, $dbname, $server_port, $server_socket, $client_flags); } }
function getConnection(MySQLConnection $connection, $inTransaction) { if ($this->isConnected()) { return $this->mysqli; } $this->mysqli = mysqli_init(); $this->mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2); //Connect - With compression $connection_status = mysqli_real_connect($this->mysqli, $this->host, $this->user, $this->pass, $this->db, $this->port, null, $this->compression ? MYSQLI_CLIENT_COMPRESS : 0); if (!$connection_status) { $this->mysqli = null; throw new ConnectionException($connection->__toString(), $connection->error()); } return $this->mysqli; }
/** * 连接数据库 * @param array $array 数据库连接配置 * $array=array( * 'dbmysql_server', * 'dbmysql_username', * 'dbmysql_password', * 'dbmysql_name', * 'dbmysql_pre', * 'dbmysql_port', * 'persistent' 'engine') * @return bool */ function Open($array) { $db = mysqli_init(); if ($array[6] == true) { $array[0] = 'p:' . $array[0]; } //mysqli_options($db,MYSQLI_READ_DEFAULT_GROUP,"max_allowed_packet=50M"); mysqli_real_connect($db, $array[0], $array[1], $array[2], $array[3], $array[5]); mysqli_set_charset($db, 'utf8'); $this->db = $db; $this->dbname = $array[3]; $this->dbpre = $array[4]; $this->dbengine = $array[7]; return true; }
function connect($host, $username, $password, $database) { $link = mysqli_init(); if (!$link) { error_log('mysqli_init failed'); return false; } # TODO: Allow setting options like connection timeout: http://www.php.net/manual/en/mysqli.options.php if (!mysqli_real_connect($link, $host, $username, $password, $database)) { error_log('mysqli_real_connect error: (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); return false; } _link($link); return $link; }
/** * Connect to database * */ protected function _connect($params) { if (!extension_loaded('mysqli')) { throw new Cola_Com_Db_Exception('NO_MYSQLI_EXTENSION_FOUND'); } if ($params['persistent']) { throw new Cola_Com_Db_Exception('MYSQLI_EXTENSTION_DOES_NOT_SUPPORT_PERSISTENT_CONNECTION'); } $this->_connection = mysqli_init(); $connected = @mysqli_real_connect($this->_connection, $params['host'], $params['user'], $params['password'], $params['database'], $params['port']); if (false === $connected) { throw new Cola_Com_Db_Exception($this->error()); } $this->query("SET NAMES '" . $this->_config['charset'] . "';"); }
function vbseodb_connect($server, $user, $password, $usepconnect, $tableprefix = '', $database, $port) { global $vbulletin, $DB_site, $config; if (!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $tableprefix); } if (0 == $this->link_id) { $this->mysqli = $config['Database']['dbtype'] == 'mysqli'; if (is_object($vbulletin) && isset($vbulletin->db) && (isset($vbulletin->db->connection_slave) && ($dlnk = $vbulletin->db->connection_slave) || isset($vbulletin->db->connection_master) && ($dlnk = $vbulletin->db->connection_master)) && (@is_object($dlnk) ? @mysqli_get_server_info($dlnk) : @mysql_get_server_info($dlnk))) { $this->link_id = $dlnk; } else { if (isset($DB_site) && $DB_site->link_id) { $this->link_id = $DB_site->link_id; } else { $this->own_link = 1; if ($usepconnect == 1) { $this->link_id = @mysql_pconnect($server . ($port && $port != 3306 ? ':' . $port : ''), $user, $password); } else { if ($this->mysqli) { $this->link_id = mysqli_init(); @mysqli_real_connect($this->link_id, $server, $user, $password, $database, $port); } else { $this->link_id = @mysql_connect($server . ($port && $port != 3306 ? ':' . $port : ''), $user, $password); } } } } if (!$this->link_id) { return false; } $this->mysqli = @is_object($this->link_id); if ($this->mysqli) { $this->funcs = array('get_server_info' => 'mysqli_get_server_info', 'select_db' => 'mysqli_select_db', 'query' => 'mysqli_query', 'affected_rows' => 'mysqli_affected_rows', 'num_rows' => 'mysqli_num_rows', 'free_result' => 'mysqli_free_result', 'fetch_array' => 'mysqli_fetch_array', 'fetch_assoc' => 'mysqli_fetch_assoc', 'close' => 'mysqli_close'); } else { $this->funcs = array('get_server_info' => 'mysql_get_server_info', 'select_db' => 'mysql_select_db', 'query' => 'mysql_query', 'affected_rows' => 'mysql_affected_rows', 'num_rows' => 'mysql_num_rows', 'free_result' => 'mysql_free_result', 'fetch_array' => 'mysql_fetch_array', 'fetch_assoc' => 'mysql_fetch_assoc', 'close' => 'mysql_close'); $this->vbseodb_select_db($database); } if (isset($config['Mysqli']['charset']) && ($charset = $config['Mysqli']['charset'])) { if ($this->mysqli && function_exists('mysqli_set_charset')) { mysqli_set_charset($this->link_id, $charset); } else { $this->vbseodb_query("SET NAMES {$charset}"); } } $this->mysql_version = function_exists($this->funcs['get_server_info']) ? $this->funcs['get_server_info']($this->link_id) : ''; return true; } }
function __construct($db=NULL){ // load sqlee.php (hope there is a valid db connx! make new object and use the band_aid method couldn't get auto load to work properly :/ if(is_string($db)){ $this->db = mysqli_init(); $db = explode(' ',$db); if (!$this->db) die('mysqli_init failed'); if (!mysqli_real_connect($this->db, $db[0], $db[1], $db[2],$db[3])) die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); unset($db); }elseif($db==NULL || $db=='') { die("\n<h1>Please use valid mysqli object</h1>"); } ; }
public function Connect() { /*$this->link = new MySQLi($this->host, $this->user, $this->pass); $this->link->select_db($this->dbName); $this->link->set_charset("utf8");*/ $this->link = mysqli_init(); mysqli_options($this->link, MYSQLI_OPT_LOCAL_INFILE, true); mysqli_real_connect($this->link, $this->host, $this->user, $this->pass, $this->dbName); $this->link->select_db($this->dbName); $this->link->set_charset("utf8"); if (mysqli_connect_errno()) { return mysqli_connect_error(); } else { return $this->link; } }
public function connect() { $this->_time(); $this->conn = mysqli_init(); @mysqli_real_connect($this->conn, $this->host, $this->user, $this->pass, $this->database, $this->port, $this->socket, MYSQLI_CLIENT_COMPRESS); if (mysqli_connect_errno($this->conn)) { $this->error(mysqli_connect_error($this->conn), mysqli_connect_errno($this->conn)); } if (mysqli_error($this->conn)) { $this->error(mysqli_error($this->conn), mysqli_errno($this->conn)); } mysqli_query($this->conn, "SET NAMES 'utf8'"); mysqli_query($this->conn, "SET sql_mode=''"); $this->_time(); return $this->conn; }
/** * @return MySQLim **/ public function connect() { if ($this->persistent) { throw new UnsupportedMethodException(); } $this->link = mysqli_init(); try { mysqli_real_connect($this->link, $this->hostname, $this->username, $this->password, $this->basename, $this->port, null, MYSQLI_CLIENT_FOUND_ROWS); } catch (BaseException $e) { throw new DatabaseException('can not connect to MySQL server: ' . $e->getMessage()); } if ($this->encoding) { $this->setDbEncoding(); } return $this; }