/** +---------------------------------------------------------- * 连接数据库方法 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } $conn = $this->pconnect ? 'ibase_pconnect' : 'ibase_connect'; $this->linkID[$linkNum] = $conn($config['hostname'] . '/' . $config['hostport'] . ':' . $config['database'], $config['username'], $config['password']); if (!$this->linkID[$linkNum]) { throw_exception(ibase_errmsg()); return False; } //剑雷 2007.12.28 if (($svc = ibase_service_attach($config['hostname'], $config['username'], $config['password'])) != FALSE) { $ibase_info = ibase_server_info($svc, IBASE_SVC_SERVER_VERSION) . '/' . ibase_server_info($svc, IBASE_SVC_IMPLEMENTATION); ibase_service_detach($svc); } else { $ibase_info = 'Unable to Determine'; } $this->dbVersion = $ibase_info; // 标记连接成功 $this->connected = true; // 注销数据库连接配置信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
/** * Export * * @param string $filename * @return mixed */ protected function _backup($filename) { if ($service = ibase_service_attach($this->db->hostname, $this->db->username, $this->db->password)) { $res = ibase_backup($service, $this->db->database, $filename . '.fbk'); // Close the service connection ibase_service_detach($service); return $res; } return FALSE; }
/** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . ($port ? ':' . $port : ''); $this->dbname = $database; $this->db_connect_id = $this->persistency ? @ibase_pconnect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3); $this->service_handle = function_exists('ibase_service_attach') ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; return $this->db_connect_id ? $this->db_connect_id : $this->sql_error(''); }
function connect($server, $username, $password) { $this->_link = ibase_connect($server, $username, $password); if ($this->_link) { $url_parts = explode(':', $server); $this->service_link = ibase_service_attach($url_parts[0], $username, $password); $this->server_info = ibase_server_info($this->service_link, IBASE_SVC_SERVER_VERSION); } else { $this->errno = ibase_errcode(); $this->error = ibase_errmsg(); } return (bool) $this->_link; }
/** * Database version number * * @return string */ public function version() { if (isset($this->data_cache['version'])) { return $this->data_cache['version']; } if ($service = ibase_service_attach($this->hostname, $this->username, $this->password)) { $this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); // Don't keep the service open ibase_service_detach($service); return $this->data_cache['version']; } return FALSE; }
/** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . ($port ? ':' . $port : ''); $this->dbname = str_replace('\\', '/', $database); // There are three possibilities to connect to an interbase db if (!$this->server) { $use_database = $this->dbname; } else { if (strpos($this->server, '//') === 0) { $use_database = $this->server . $this->dbname; } else { $use_database = $this->server . ':' . $this->dbname; } } $this->db_connect_id = $this->persistency ? @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); $this->service_handle = function_exists('ibase_service_attach') && $this->server ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; return $this->db_connect_id ? $this->db_connect_id : $this->sql_error(''); }
/** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . ($port ? ':' . $port : ''); $this->dbname = str_replace('\\', '/', $database); // There are three possibilities to connect to an interbase db if (!$this->server) { $use_database = $this->dbname; } else { if (strpos($this->server, '//') === 0) { $use_database = $this->server . $this->dbname; } else { $use_database = $this->server . ':' . $this->dbname; } } if ($this->persistency) { if (!function_exists('ibase_pconnect')) { $this->connect_error = 'ibase_pconnect function does not exist, is interbase extension installed?'; return $this->sql_error(''); } $this->db_connect_id = @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3); } else { if (!function_exists('ibase_connect')) { $this->connect_error = 'ibase_connect function does not exist, is interbase extension installed?'; return $this->sql_error(''); } $this->db_connect_id = @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); } // Do not call ibase_service_attach if connection failed, // otherwise error message from ibase_(p)connect call will be clobbered. if ($this->db_connect_id && function_exists('ibase_service_attach') && $this->server) { $this->service_handle = @ibase_service_attach($this->server, $this->user, $sqlpassword); } else { $this->service_handle = false; } return $this->db_connect_id ? $this->db_connect_id : $this->sql_error(''); }
/** * @brief DB 접속 **/ function _connect() { // db 정보가 없으면 무시 if (!$this->hostname || !$this->port || !$this->userid || !$this->password || !$this->database) { return; } //if(strpos($this->hostname, ':')===false && $this->port) $this->hostname .= ':'.$this->port; // 접속시도 $host = $this->hostname . "/" . $this->port . ":" . $this->database; $this->fd = @ibase_connect($host, $this->userid, $this->password); if (ibase_errmsg()) { $this->setError(ibase_errcode(), ibase_errmsg()); return $this->is_connected = false; } // Firebird 버전 확인후 2.0 이하면 오류 표시 if (($service = ibase_service_attach($this->hostname, $this->userid, $this->password)) != FALSE) { // get server version and implementation strings $server_info = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); ibase_service_detach($service); } else { $this->setError(ibase_errcode(), ibase_errmsg()); @ibase_close($this->fd); return $this->is_connected = false; } $pos = strpos($server_info, "Firebird"); if ($pos !== false) { $ver = substr($server_info, $pos + strlen("Firebird")); $ver = trim($ver); } if ($ver < "2.0") { $this->setError(-1, "XE cannot be installed under the version of firebird 2.0. Current firebird version is " . $ver); @ibase_close($this->fd); return $this->is_connected = false; } // 접속체크 $this->is_connected = true; }
/** * return version information about the server * * @param bool $native determines if the raw version string should be returned * @return mixed array/string with version information or MDB2 error object * @access public */ function getServerVersion($native = false) { $server_info = false; if ($this->connected_server_info) { $server_info = $this->connected_server_info; } elseif ($this->options['server_version']) { $server_info = $this->options['server_version']; } else { $username = $this->options['DBA_username'] ? $this->options['DBA_username'] : $this->dsn['username']; $password = $this->options['DBA_password'] ? $this->options['DBA_password'] : $this->dsn['password']; $ibserv = @ibase_service_attach($this->dsn['hostspec'], $username, $password); $server_info = @ibase_server_info($ibserv, IBASE_SVC_SERVER_VERSION); @ibase_service_detach($ibserv); } if (!$server_info) { return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'Requires either "server_version" or "DBA_username"/"DBA_password" option', __FUNCTION__); } // cache server_info $this->connected_server_info = $server_info; if (!$native) { //WI-V1.5.3.4854 Firebird 1.5 //WI-T2.1.0.16780 Firebird 2.1 Beta 2 if (!preg_match('/-[VT]([\\d\\.]*)/', $server_info, $matches)) { return $this->raiseError(MDB2_ERROR_INVALID, null, null, 'Could not parse version information:' . $server_info, __FUNCTION__); } $tmp = explode('.', $matches[1], 4); $server_info = array('major' => isset($tmp[0]) ? $tmp[0] : null, 'minor' => isset($tmp[1]) ? $tmp[1] : null, 'patch' => isset($tmp[2]) ? $tmp[2] : null, 'extra' => isset($tmp[3]) ? $tmp[3] : null, 'native' => $server_info); } return $server_info; }
/** * Version number query string * * @access public * @return string */ function _version() { if (($svc = ibase_service_attach($this->hostname, $this->username, $this->password)) != FALSE) { $ibase_info = ibase_server_info($svc, IBASE_SVC_SERVER_VERSION) . '/' . ibase_server_info($svc, IBASE_SVC_IMPLEMENTATION); ibase_service_detach($svc); } else { $ibase_info = 'Unable to Determine'; } return $ibase_info; }
/** * Retrieve server version in PHP style * * @return string */ public function getServerVersion() { $this->_connect(); $service = ibase_service_attach($this->_formatDbConnString($this->_config['host'], $this->_config['port'], ''), $this->_config['username'], $this->_config['password']); if ($service != FALSE) { $server_info = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); ibase_service_detach($service); $matches = null; if (preg_match('/((?:[0-9]{1,2}\\.){1,3}[0-9]{1,2})/', $server_info, $matches)) { return $matches[1]; } else { return null; } } else { return null; } }
public function backup($filename = '') { if ($service = ibase_service_attach($this->config['host'], $this->config['user'], $this->config['password'])) { $backup = ibase_backup($service, $this->config['database'], $filename . '.fbk'); ibase_service_detach($service); return $backup; } return false; }