function F2MysqlClass($DBHost, $DBUser, $DBPswd, $DBName, $DBNewlink = "false", $debug = false) { if ($DBNewlink == "true") { if (!mysql_pconnect($DBHost, $DBUser, $DBPswd)) { $this->halt("Don't connect to database!"); } } else { if (!mysql_connect($DBHost, $DBUser, $DBPswd)) { $this->halt("Don't connect to database!"); } } if ($this->getServerInfo() > '4.1') { mysql_query("SET NAMES 'utf8'"); } if ($this->getServerInfo() > '5.0.1') { mysql_query("SET sql_mode=''"); } if ($DBName) { $this->selectDB($DBName); } if ($debug) { $this->_debug = $debug; $this->_fp = fopen(F2BLOG_ROOT . "./cache/" . date("Ymd") . ".log", "a"); } }
/** * Persistent database connection * * @access private called by the base class * @return resource */ private function db_pconnect() { if ($this->port != '') { $this->db_hostname .= ':' . $this->port; } return @mysql_pconnect($this->db_hostname, $this->db_username, $this->db_password); }
/** +---------------------------------------------------------- * 连接数据库方法 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } // 处理不带端口号的socket连接情况 $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : ''); if ($this->pconnect) { $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], CLIENT_MULTI_RESULTS); } else { $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, CLIENT_MULTI_RESULTS); } if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) { throw_exception(mysql_error()); } $dbVersion = mysql_get_server_info($this->linkID[$linkNum]); if ($dbVersion >= "4.1") { //使用UTF8存取数据库 需要mysql 4.1.0以上支持 mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]); } //设置 sql_model if ($dbVersion > '5.0.1') { mysql_query("SET sql_mode=''", $this->linkID[$linkNum]); } // 标记连接成功 $this->connected = true; // 注销数据库连接配置信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
function Open($dbType, $connectType = "c", $connect, $username = "", $password = "", $dbName) { switch ($dbType) { case "mssql": if ($connectType == "c") { $idCon = mssql_connect($connect, $username, $password); } else { $idCon = mssql_pconnect($connect, $username, $password); } mssql_select_db($dbName); break; case "mysql": if ($connectType == "c") { $idCon = @mysql_connect($connect, $username, $password); } else { $idCon = @mysql_pconnect($connect, $username, $password); } $idCon1 = mysql_select_db($dbName, $idCon); break; case "pg": if ($connectType == "c") { $idCon = pg_connect($connect . " user="******" password="******" dbname=" . $dbName); } else { $idCon = pg_pconnect($connect . " user="******" password="******" dbname=" . $dbName); } break; default: $idCon = 0; break; } return $idCon; }
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) { $this->persistency = $persistency; $this->user = $sqluser; $this->password = $sqlpassword; $this->server = $sqlserver; $this->dbname = $database; if ($this->persistency) { $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password); } else { $this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password); } if ($this->db_connect_id) { if ($database != "") { $this->dbname = $database; $dbselect = @mysql_select_db($this->dbname); if (!$dbselect) { @mysql_close($this->db_connect_id); $this->db_connect_id = $dbselect; } } return $this->db_connect_id; } else { return false; } }
function getID3_cached_mysql($host, $database, $username, $password) { // Check for mysql support if (!function_exists('mysql_pconnect')) { throw new Exception('PHP not compiled with mysql support.'); } // Connect to database $this->connection = mysql_pconnect($host, $username, $password); if (!$this->connection) { throw new Exception('mysql_pconnect() failed - check permissions and spelling.'); } // Select database if (!mysql_select_db($database, $this->connection)) { throw new Exception('Cannot use database ' . $database); } // Create cache table if not exists $this->create_table(); // Check version number and clear cache if changed $version = ''; if ($this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename` = '" . mysql_real_escape_string(GETID3_VERSION) . "') AND (`filesize` = '-1') AND (`filetime` = '-1') AND (`analyzetime` = '-1')", $this->connection)) { list($version) = mysql_fetch_array($this->cursor); } if ($version != GETID3_VERSION) { $this->clear_cache(); } parent::getID3(); }
function DoConnect() { if ($this->bConnected) { return; } $this->bConnected = true; if (DBPersistent && !$this->bNodeConnection) { $this->db_Conn = @mysql_pconnect($this->DBHost, $this->DBLogin, $this->DBPassword); } else { $this->db_Conn = @mysql_connect($this->DBHost, $this->DBLogin, $this->DBPassword, true); } if (!$this->db_Conn) { $s = DBPersistent && !$this->bNodeConnection ? "mysql_pconnect" : "mysql_connect"; if ($this->debug || @session_start() && $_SESSION["SESS_AUTH"]["ADMIN"]) { echo "<br><font color=#ff0000>Error! " . $s . "('-', '-', '-')</font><br>" . mysql_error() . "<br>"; } SendError("Error! " . $s . "('-', '-', '-')\n" . mysql_error() . "\n"); return false; } if (!mysql_select_db($this->DBName, $this->db_Conn)) { if ($this->debug || @session_start() && $_SESSION["SESS_AUTH"]["ADMIN"]) { echo "<br><font color=#ff0000>Error! mysql_select_db(" . $this->DBName . ")</font><br>" . mysql_error($this->db_Conn) . "<br>"; } SendError("Error! mysql_select_db(" . $this->DBName . ")\n" . mysql_error($this->db_Conn) . "\n"); return false; } $this->cntQuery = 0; $this->timeQuery = 0; $this->arQueryDebug = array(); global $DB, $USER, $APPLICATION; if (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/after_connect.php")) { include $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/after_connect.php"; } return true; }
/** +---------------------------------------------------------- * 连接数据库方法 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function connect() { if (!$this->connected) { $config = $this->config; // 处理不带端口号的socket连接情况 $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : ''); if ($this->pconnect) { $this->linkID = mysql_pconnect($host, $config['username'], $config['password']); } else { $this->linkID = mysql_connect($host, $config['username'], $config['password'], true); } if (!$this->linkID || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID)) { echo mysql_error(); } $dbVersion = mysql_get_server_info($this->linkID); if ($dbVersion >= "4.1") { //使用UTF8存取数据库 需要mysql 4.1.0以上支持 mysql_query("SET NAMES 'UTF8'", $this->linkID); } //设置 sql_model if ($dbVersion > '5.0.1') { mysql_query("SET sql_mode=''", $this->linkID); } // 标记连接成功 $this->connected = true; // 注销数据库连接配置信息 unset($this->config); } }
public function __construct($host, $database, $username, $password, $table = 'getid3_cache') { // Check for mysql support if (!function_exists('mysql_pconnect')) { throw new Exception('PHP not compiled with mysql support.'); } // Connect to database $this->connection = mysql_pconnect($host, $username, $password); if (!$this->connection) { throw new Exception('mysql_pconnect() failed - check permissions and spelling.'); } // Select database if (!mysql_select_db($database, $this->connection)) { throw new Exception('Cannot use database ' . $database); } // Set table $this->table = $table; // Create cache table if not exists $this->create_table(); // Check version number and clear cache if changed $version = ''; $SQLquery = 'SELECT `value`'; $SQLquery .= ' FROM `' . mysql_real_escape_string($this->table) . '`'; $SQLquery .= ' WHERE (`filename` = \'' . mysql_real_escape_string(getID3::VERSION) . '\')'; $SQLquery .= ' AND (`filesize` = -1)'; $SQLquery .= ' AND (`filetime` = -1)'; $SQLquery .= ' AND (`analyzetime` = -1)'; if ($this->cursor = mysql_query($SQLquery, $this->connection)) { list($version) = mysql_fetch_array($this->cursor); } if ($version != getID3::VERSION) { $this->clear_cache(); } parent::__construct(); }
function connect() { global $usepconnect; // connect to db server if (0 == $this->link_id) { if ($this->password == "") { if ($usepconnect == 1) { $this->link_id = mysql_pconnect($this->server, $this->user); } else { $this->link_id = mysql_connect($this->server, $this->user); } } else { if ($usepconnect == 1) { $this->link_id = mysql_pconnect($this->server, $this->user, $this->password); } else { $this->link_id = mysql_connect($this->server, $this->user, $this->password); } } if (!$this->link_id) { $this->halt("Link-ID == false, connect failed"); } if ($this->database != "") { if (!mysql_select_db($this->database, $this->link_id)) { $this->halt("cannot use database " . $this->database); } } } }
function PMA_DBI_connect($user, $password) { global $cfg, $php_errormsg; $server_port = empty($cfg['Server']['port']) ? '' : ':' . $cfg['Server']['port']; if (strtolower($cfg['Server']['connect_type']) == 'tcp') { $cfg['Server']['socket'] = ''; } $server_socket = empty($cfg['Server']['socket']) ? '' : ':' . $cfg['Server']['socket']; if (PMA_PHP_INT_VERSION >= 40300 && PMA_MYSQL_CLIENT_API >= 32349) { $client_flags = $cfg['Server']['compress'] && defined('MYSQL_CLIENT_COMPRESS') ? MYSQL_CLIENT_COMPRESS : 0; // always use CLIENT_LOCAL_FILES as defined in mysql_com.h // for the case where the client library was not compiled // with --enable-local-infile $client_flags |= 128; } if (empty($client_flags)) { $connect_func = 'mysql_' . ($cfg['PersistentConnections'] ? 'p' : '') . 'connect'; $link = @$connect_func($cfg['Server']['host'] . $server_port . $server_socket, $user, $password); } else { if ($cfg['PersistentConnections']) { $link = @mysql_pconnect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, $client_flags); } else { $link = @mysql_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, FALSE, $client_flags); } } if (empty($link)) { PMA_auth_fails(); } // end if PMA_DBI_postConnect($link); return $link; }
public function connect() { /** if ($this->conn == "pconn") { //永久链接 $this->conn = mysql_pconnect($this->db_host, $this->db_user, $this->db_pwd); } else { //即时链接 $this->conn = mysql_connect($this->db_host, $this->db_user, $this->db_pwd); } if (!mysql_select_db($this->db_database, $this->conn)) { if ($this->show_error) { $this->show_error("数据库不可用:", $this->db_database); } } mysql_query("SET NAMES $this->coding"); **/ if ($this->conn == "pconn") { //永久链接 $this->conn = mysql_pconnect($this->db_host, $this->db_user, $this->db_pwd); } else { //即时链接 $this->conn = mysqli_connect($this->db_host, $this->db_user, $this->db_pwd, $this->db_database); } if (mysqli_connect_errno($this->conn)) { $this->show_error("数据库不可用:", $this->db_database); } mysqli_query($this->conn, "SET NAMES {$this->coding}"); }
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset, $pconnect = 0, $tablepre = '', $time = 0) { $this->tablepre = $tablepre; if ($pconnect) { if (!($this->link = mysql_pconnect($dbhost, $dbuser, $dbpw))) { die('Can not connect to MySQL server'); } } else { if (!($this->link = mysql_connect($dbhost, $dbuser, $dbpw, 1))) { die('Can not connect to MySQL server'); } } if ($this->version() > '4.1') { if ($dbcharset) { mysql_query("SET character_set_connection=" . $dbcharset . ", character_set_results=" . $dbcharset . ", character_set_client=binary", $this->link); } if ($this->version() > '5.0.1') { mysql_query("SET sql_mode=''", $this->link); } } if ($dbname) { $db_selected = mysql_select_db($dbname, $this->link); if (!$db_selected) { $sql = "CREATE DATABASE {$dbname} DEFAULT CHARACTER SET utf8;"; self::query($sql); mysql_select_db($dbname, $this->link); } } }
function connect($db, $return = false) { if ($db['port']) { $db['server'] .= ':' . $db['port']; } if ($this->link_identifier) { $this->disconnect(); } $this->link_identifier = $db['persistent'] ? @mysql_pconnect($db['server'], $db['username'], $db['password']) : @mysql_connect($db['server'], $db['username'], $db['password']); if ($this->link_identifier) { if (@mysql_select_db($db['database'])) { mysql_query('SET NAMES utf8', $this->link_identifier); //mysql_query('SET character_set_results = NULL', $this->link_identifier); return $this->link_identifier; } $error = '<center>There is currently a problem with the site<br/>Please try again later<br /><br />Error Code: DB2</center>'; } if (!$this->report_error) { return false; } if (!isset($error)) { $error = '<center>There is currently a problem with the site<br/>Please try again later<br /><br />Error Code: DB1</center>'; } $this->disconnect(); trigger_error($error, E_USER_ERROR); }
public function __construct() { // attempt to connect if (!($this->db = !$_SERVER['tracker']['db_persist'] ? mysql_connect($_SERVER['tracker']['db_host'], $_SERVER['tracker']['db_user'], $_SERVER['tracker']['db_pass']) : mysql_pconnect($_SERVER['tracker']['db_host'], $_SERVER['tracker']['db_user'], $_SERVER['tracker']['db_pass'])) or !mysql_select_db($_SERVER['tracker']['db_name'], $this->db)) { tracker_error(mysql_errno($this->db) . ' - ' . mysql_error($this->db)); } }
function connect() { if ($this->pconnect) { if (!($this->dou_link = @mysql_pconnect($this->dbhost, $this->dbuser, $this->dbpass))) { $this->error('Can not pconnect to mysql server'); return false; } } else { if (!($this->dou_link = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpass, true))) { $this->error('Can not connect to mysql server'); return false; } } if ($this->version() > '4.1') { if ($this->charset) { $this->query("SET character_set_connection=" . $this->charset . ", character_set_results=" . $this->charset . ", character_set_client=binary"); } if ($this->version() > '5.0.1') { $this->query("SET sql_mode=''"); } } if (mysql_select_db($this->dbname, $this->dou_link) === false) { $this->error("NO THIS DBNAME:" . $this->dbname); return false; } }
public function connect() { if ($this->_connection) { return $this->_connection; } extract($this->_config['connection']); unset($this->_config['connection']); try { if ($persistent) { $this->_connection = mysql_pconnect($hostname, $username, $password); } else { $this->_connection = mysql_connect($hostname, $username, $password, TRUE); } } catch (Exception $e) { $this->_connection = NULL; throw new Kohana_Exception(':error', array(':error' => $e->getMessage()), $e->getCode()); } if (!mysql_select_db($database, $this->_connection)) { throw new Kohana_Exception(':error', array(':error' => mysql_error($this->_connection)), mysql_errno($this->_connection)); } if (!empty($this->_config['charset'])) { $this->set_charset($this->_config['charset']); } return $this->_connection; }
/** * 连接数据库方法 * @access public * @throws ThinkExecption */ public function connect() { if (!$this->connected) { $config = $this->config; // 处理不带端口号的socket连接情况 $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : ''); $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect; if ($pconnect) { $this->linkID = mysql_pconnect($host, $config['username'], $config['password'], CLIENT_MULTI_RESULTS); } else { $this->linkID = mysql_connect($host, $config['username'], $config['password'], true, CLIENT_MULTI_RESULTS); } if (!$this->linkID || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID)) { throw_exception(mysql_error()); } $dbVersion = mysql_get_server_info($this->linkID); if ($dbVersion >= "4.1") { //使用UTF8存取数据库 需要mysql 4.1.0以上支持 mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID); } //设置 sql_model if ($dbVersion > '5.0.1') { mysql_query("SET sql_mode=''", $this->linkID); } // 标记连接成功 $this->connected = true; // 注销数据库连接配置信息 unset($this->config); } }
public function connect() { if ($this->_connection) { return; } if (static::$_set_names === NULL) { // Determine if we can use mysql_set_charset(), which is only // available on PHP 5.2.3+ when compiled against MySQL 5.0+ static::$_set_names = !function_exists('mysql_set_charset'); } // Extract the connection parameters, adding required variabels extract($this->_config['connection'] + array('database' => '', 'hostname' => '', 'username' => '', 'password' => '', 'persistent' => FALSE)); // Prevent this information from showing up in traces unset($this->_config['connection']['username'], $this->_config['connection']['password']); try { if ($persistent) { // Create a persistent connection $this->_connection = mysql_pconnect($hostname, $username, $password); } else { // Create a connection and force it to be a new link $this->_connection = mysql_connect($hostname, $username, $password, TRUE); } } catch (ErrorException $e) { // No connection exists $this->_connection = NULL; throw new \Database_Exception(mysql_error(), mysql_errno()); } // \xFF is a better delimiter, but the PHP driver uses underscore $this->_connection_id = sha1($hostname . '_' . $username . '_' . $password); $this->_select_db($database); if (!empty($this->_config['charset'])) { // Set the character set $this->set_charset($this->_config['charset']); } }
/** * * @param $server * @param $username * @param $password * @param $db_name * @param $persistency * @return unknown_type */ public function __construct($server, $username, $password, $db_name = null, $persistency = true) { if ($persistency) { $this->link = @mysql_pconnect($server, $username, $password); } else { $this->link = @mysql_connect($server, $username, $password, true); } if (!$this->link) { if (mysql_errno()) { throw new MySqlException(mysql_error(), mysql_errno()); } else { throw new MySqlException("Can't connect to MySQL server on '{$server}'", 2003); } } if ($db_name !== null) { if (!$this->selectDatabase($db_name)) { if (mysql_errno()) { $error = mysql_error(); $errno = mysql_errno(); } else { $error = "Error selecting database '{$db_name}' on host '{$server}'"; $errno = 1049; } @mysql_close($this->link); throw new MySqlException($error, $errno); } } }
function connect($pconnect = false, $force_new = false) { if (is_resource($this->_conn)) { return; } $this->_last_err = null; $this->_last_err_code = null; if (isset($this->_dsn['port']) && $this->_dsn['port'] != '') { $host = $this->_dsn['host'] . ':' . $this->_dsn['port']; } else { $host = $this->_dsn['host']; } if (!isset($this->_dsn['login'])) { $this->_dsn['login'] = ''; } if (!isset($this->_dsn['password'])) { $this->_dsn['password'] = ''; } if ($pconnect) { $this->_conn = mysql_pconnect($host, $this->_dsn['login'], $this->_dsn['password'], $force_new); } else { $this->_conn = mysql_connect($host, $this->_dsn['login'], $this->_dsn['password'], $force_new); } if (!is_resource($this->_conn)) { throw new QDB_Exception('CONNECT DATABASE', mysql_error(), mysql_errno()); } if (!empty($this->_dsn['database'])) { $this->execute('USE ' . $this->qid($this->_dsn['database'])); } if (isset($this->_dsn['charset']) && $this->_dsn['charset'] != '') { $charset = $this->_dsn['charset']; $this->execute("SET NAMES '" . $charset . "'"); } }
function conn($host = 'localhost', $user = '******', $pass = '******', $db = 'database') { $this->host = $host; $this->user = $user; $this->pass = $pass; $this->db = $db; if ($this->persistant) { $this->db_link = mysql_pconnect($this->host, $this->user, $this->pass, true); } else { $this->db_link = mysql_connect($this->host, $this->user, $this->pass, true); } if (!$this->db_link) { if ($this->error) { $this->error($type = 1); } return false; } else { if (empty($db)) { if ($this->error) { $this->error($type = 2); } } else { $db = mysql_select_db($this->db, $this->db_link); if (!$db) { if ($this->error) { $this->error($type = 2); } return false; } $this->conn = true; } return $this->db_link; } }
/** * 连接数据库方法 * @access public * @throws ThinkExecption */ public function connect($config = '', $linkNum = 0, $force = false) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } // 处理不带端口号的socket连接情况 $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : ''); // 是否长连接 $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect; if ($pconnect) { $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], CLIENT_MULTI_RESULTS); } else { $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, CLIENT_MULTI_RESULTS); } if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum]) || C('SPARE_DB_DEBUG')) { $errStr = mysql_error(); $errno = mysql_errno(); if ($errno == 13047 || C('SPARE_DB_DEBUG')) { if (C('SMS_ALERT_ON')) { Sms::send('mysql超额被禁用,请在SAE日志中心查看详情', $errStr, Sms::MYSQL_ERROR); } //[sae]启动备用数据库 if (C('SPARE_DB_HOST')) { $this->linkID[$linkNum] = mysql_connect(C('SPARE_DB_HOST') . (C('SPARE_DB_PORT') ? ':' . C('SPARE_DB_PORT') : ''), C('SPARE_DB_USER'), C('SPARE_DB_PWD'), true, CLIENT_MULTI_RESULTS); if (!$this->linkID[$linkNum]) { throw_exception('备用数据库连接失败'); } mysql_select_db(C('SPARE_DB_NAME'), $this->linkID[$linkNum]); //标记使用备用数据库状态 $this->is_spare = true; } else { throw_exception($errStr); } } else { //[sae] 短信预警 if (C('SMS_ALERT_ON')) { Sms::send('数据库连接时出错,请在SAE日志中心查看详情', $errStr, Sms::MYSQL_ERROR); } throw_exception($errStr); } } $dbVersion = mysql_get_server_info($this->linkID[$linkNum]); if ($dbVersion >= '4.1') { //使用UTF8存取数据库 需要mysql 4.1.0以上支持 mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]); } //设置 sql_model if ($dbVersion > '5.0.1') { mysql_query("SET sql_mode=''", $this->linkID[$linkNum]); } // 标记连接成功 $this->connected = true; // 注销数据库连接配置信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
/** * connect to the database * * @param bool $selectdb select the database now? * @return bool successful? */ public function connect($selectdb = true) { static $db_charset_set; $this->allowWebChanges = $_SERVER['REQUEST_METHOD'] != 'GET'; if (!extension_loaded('mysql')) { trigger_error(_CORE_DB_NOTRACE, E_USER_ERROR); return false; } if (XOOPS_DB_PCONNECT == 1) { $this->conn = @mysql_pconnect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, true); // ALTERED BY FREEFORM SOLUTIONS FOR THE FORMULIZE STANDALONE RELEASE } else { $this->conn = @mysql_connect(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, true); // ALTERED BY FREEFORM SOLUTIONS FOR THE FORMULIZE STANDALONE RELEASE } if (!$this->conn) { $this->logger->addQuery('', $this->error(), $this->errno()); return false; } if ($selectdb != false) { if (!mysql_select_db(XOOPS_DB_NAME)) { $this->logger->addQuery('', $this->error(), $this->errno()); return false; } } if (!isset($db_charset_set) && defined('XOOPS_DB_CHARSET') && XOOPS_DB_CHARSET && XOOPS_DB_CHARSET !== 'ucs2') { $this->queryF("SET NAMES '" . XOOPS_DB_CHARSET . "'"); } $db_charset_set = 1; return true; }
/** * 连接数据库方法 * @access public * @throws ThinkExecption */ public function connect($config='',$linkNum=0,$force=false) { if ( !isset($this->linkID[$linkNum]) ) { if(empty($config)) $config = $this->config; // 处理不带端口号的socket连接情况 $host = $config['hostname'].($config['hostport']?":{$config['hostport']}":''); // 是否长连接 $pconnect = !empty($config['params']['persist'])? $config['params']['persist']:$this->pconnect; if($pconnect) { $this->linkID[$linkNum] = mysql_pconnect( $host, $config['username'], $config['password'],131072); }else{ $this->linkID[$linkNum] = mysql_connect( $host, $config['username'], $config['password'],true,131072); } if ( !$this->linkID[$linkNum] || (!empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) ) { E(mysql_error()); } $dbVersion = mysql_get_server_info($this->linkID[$linkNum]); //使用UTF8存取数据库 mysql_query("SET NAMES '".C('DB_CHARSET')."'", $this->linkID[$linkNum]); //设置 sql_model if($dbVersion >'5.0.1'){ mysql_query("SET sql_mode=''",$this->linkID[$linkNum]); } // 标记连接成功 $this->connected = true; // 注销数据库连接配置信息 if(1 != C('DB_DEPLOY_TYPE')) unset($this->config); } return $this->linkID[$linkNum]; }
function connect($Database = "", $Host = "", $User = "", $Password = "") { /* Handle defaults */ if ("" == $Database) { $Database = $this->Database; } if ("" == $Host) { $Host = $this->Host; } if ("" == $User) { $User = $this->User; } if ("" == $Password) { $Password = $this->Password; } /* establish connection, select database */ if (0 == $this->Link_ID) { $this->Link_ID = mysql_pconnect($Host, $User, $Password); if (!$this->Link_ID) { //echo $Database; $this->halt("connect({$Host}, {$User}, \$Password) failed."); return 0; } if (!@mysql_select_db($Database, $this->Link_ID)) { $this->halt("cannot use database " . $this->Database); return 0; } } return $this->Link_ID; }
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset = '', $pconnect = 0, $tablepre = '', $time = 0) { $this->dbhost = $dbhost; $this->dbuser = $dbuser; $this->dbpw = $dbpw; $this->dbname = $dbname; $this->dbcharset = $dbcharset; $this->pconnect = $pconnect; $this->tablepre = $tablepre; $this->time = $time; if ($pconnect) { if (!($this->link = mysql_pconnect($dbhost, $dbuser, $dbpw))) { $this->halt('Can not connect to MySQL server'); } } else { if (!($this->link = mysql_connect($dbhost, $dbuser, $dbpw))) { $this->halt('Can not connect to MySQL server'); } } if ($this->version() > '4.1') { if ($dbcharset) { mysql_query("SET character_set_connection=" . $dbcharset . ", character_set_results=" . $dbcharset . ", character_set_client=binary", $this->link); } if ($this->version() > '5.0.1') { //mysql_query("SET sql_mode=''", $this->link); //关闭严格模式 } } if ($dbname) { mysql_select_db($dbname, $this->link); } }
public function connect($user, $pass, $db, $host = "localhost") { $this->database = $db; // Connect to the database if ($this->connected) { return $this->link_identifier; } if ($this->persistent_connect) { $this->link_identifier = @mysql_pconnect($host, $user, $pass, $this->new_link); } else { $this->link_identifier = @mysql_connect($host, $user, $pass, $this->new_link); } if ($this->link_identifier) { $select = @mysql_select_db($db, $this->link_identifier); if (!$select) { trigger_error("Database <b>{$db}</b> doesn't exist", E_USER_ERROR); } $this->connected = true; return $this->link_identifier; } else { $this->connected = false; if ($this->die_on_fail) { trigger_error('Could not connect to the database', E_USER_ERROR); } return false; } }
function db($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset = 'utf8', $pconnect = 0) { if ($pconnect) { if (!($this->mlink = @mysql_pconnect($dbhost, $dbuser, $dbpw))) { $this->halt('Can not connect to MySQL'); } } else { if (!($this->mlink = @mysql_connect($dbhost, $dbuser, $dbpw))) { $this->halt('Can not connect to MySQL'); } } if ($this->version() > '4.1') { if ('utf-8' == strtolower($dbcharset)) { $dbcharset = 'utf8'; } if ($dbcharset) { mysql_query("SET character_set_connection={$dbcharset}, character_set_results={$dbcharset}, character_set_client=binary", $this->mlink); } if ($this->version() > '5.0.1') { mysql_query("SET sql_mode=''", $this->mlink); } } if ($dbname) { mysql_select_db($dbname, $this->mlink); } }
/** * connect stuff */ function connect() { if ($this->_connected) { return; } core::dprint(array('CONNECT %s', $this->dbname), core::E_SQL); $starttime = microtime(true); if (!function_exists('mysql_connect')) { throw new dbal_exception('MySQL support not compiled with PHP!'); } if (empty($this->dbname)) { throw new dbal_exception('Empty database given'); } $this->_connect_id = $this->persistency ? mysql_pconnect($this->server, $this->user, $this->password) : mysql_connect($this->server, $this->user, $this->password); if (empty($this->_connect_id)) { throw new dbal_exception('Cant connect to database', $this->get_error()); } $dbselect = mysql_select_db($this->dbname); if (!$dbselect) { throw new dbal_exception('Cant use database', $this->get_error()); } $endtime = microtime(true) - $starttime; $this->sql_time += $endtime; $this->_disabled_set_names = !empty($this->_config['disable_set_names']); $this->_connected = true; if (!empty($this->_config['fix_charset'])) { if ($this->_connect_id) { $this->fix_charset(); } } $this->password = null; return $this->_connect_id; }