Example #1
0
function db_connect()
{
    if (defined('CONN')) {
        return;
    }
    define('CONN', @mysql_pconnect(DBHOST, DBUSER, DBPASS));
    $db = @mysql_select_db(DBDATE, CONN);
    if (!CONN) {
        die('Verbindung nicht m&ouml;glich, bitte pr&uuml;fen Sie ihre mySQL Daten wie Passwort, Username und Host<br />');
    }
    if (!$db) {
        die('Kann Datenbank "' . DBDATE . '" nicht benutzen : ' . mysql_error(CONN));
    }
    if (function_exists('mysql_set_charset') and version_compare(mysql_get_server_info(CONN), '5.0.7') !== -1) {
        //Für ältere Installation die init.php nachladen
        if (!defined('ILCH_DB_CHARSET') && file_exists('include/includes/init.php')) {
            require_once 'include/includes/init.php';
        }
        mysql_set_charset(ILCH_DB_CHARSET, CONN);
    }
    $timeZoneSetted = false;
    if (function_exists('date_default_timezone_get')) {
        $timeZoneSetted = mysql_query('SET time_zone = "' . date_default_timezone_get() . '"');
    }
    if (!$timeZoneSetted && version_compare(PHP_VERSION, '5.1.3')) {
        $timeZoneSetted = mysql_query('SET time_zone = "' . date('P') . '"');
    }
}
Example #2
0
 /**
  * 连接数据库方法
  * @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];
 }
Example #3
0
 /**
  * DB Connect
  * this method is private
  * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
  * @return resource
  */
 function __connect($connection)
 {
     // Ignore if no DB information exists
     if (strpos($connection["db_hostname"], ':') === false && $connection["db_port"]) {
         $connection["db_hostname"] .= ':' . $connection["db_port"];
     }
     // Attempt to connect
     $result = @mysql_connect($connection["db_hostname"], $connection["db_userid"], $connection["db_password"]);
     if (!$result) {
         exit('XE cannot connect to DB.');
     }
     if (mysql_error()) {
         $this->setError(mysql_errno(), mysql_error());
         return;
     }
     // Error appears if the version is lower than 4.1
     if (version_compare(mysql_get_server_info($result), '4.1', '<')) {
         $this->setError(-1, 'XE cannot be installed under the version of mysql 4.1. Current mysql version is ' . mysql_get_server_info());
         return;
     }
     // select db
     @mysql_select_db($connection["db_database"], $result);
     if (mysql_error()) {
         $this->setError(mysql_errno(), mysql_error());
         return;
     }
     return $result;
 }
Example #4
0
function EchoConnInfo($conn)
{
	$str = GetBlock(mysql_get_host_info($conn));
	$str .= GetBlock(mysql_get_proto_info($conn));
	$str .= GetBlock(mysql_get_server_info($conn));
	echo $str;
}
Example #5
0
 function connect($db_user, $db_pass, $db_name, $db_location = 'localhost', $show_error = 1)
 {
     if (!($this->db_id = @mysql_connect($db_location, $db_user, $db_pass))) {
         if ($show_error == 1) {
             $this->display_error(mysql_error(), mysql_errno());
         } else {
             return false;
         }
     }
     if (!@mysql_select_db($db_name, $this->db_id)) {
         if ($show_error == 1) {
             $this->display_error(mysql_error(), mysql_errno());
         } else {
             return false;
         }
     }
     $this->mysql_version = mysql_get_server_info();
     if (!defined('COLLATE')) {
         define("COLLATE", "cp1251");
     }
     if (version_compare($this->mysql_version, '4.1', ">=")) {
         mysql_query("/*!40101 SET NAMES '" . COLLATE . "' */");
     }
     $this->connected = true;
     return true;
 }
 public function db_version($handle)
 {
     if (is_resource($handle)) {
         return mysql_get_server_info();
     }
     return null;
 }
Example #7
0
 /**
  * 连接数据库方法
  * @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);
     }
 }
Example #8
0
 /**
  * 连接数据库
  * param  string  $dbhost		数据库主机名<br/>
  * param  string  $dbuser		数据库用户名<br/>
  * param  string  $dbpw			数据库密码<br/>
  * param  string  $dbname		数据库名称<br/>
  * param  string  $dbcharset	数据库字符集<br />
  * param  string  $pconnect		持久链接,1为开启,0为关闭
  * return bool
  **/
 function connect($dbhost, $dbuser, $dbpwd, $dbname = '', $dbcharset = 'utf8', $pconnect = 0)
 {
     if ($pconnect) {
         if (!($this->link_id = mysql_pconnect($dbhost, $dbuser, $dbpwd))) {
             $this->ErrorMsg();
         }
     } else {
         if (!($this->link_id = mysql_connect($dbhost, $dbuser, $dbpwd, 1))) {
             $this->ErrorMsg();
         }
     }
     $this->version = mysql_get_server_info($this->link_id);
     if ($this->getVersion() > '4.1') {
         if ($dbcharset) {
             mysql_query("SET character_set_connection=" . $dbcharset . ", character_set_results=" . $dbcharset . ", character_set_client=binary", $this->link_id);
         }
         if ($this->getVersion() > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->link_id);
         }
     }
     if (mysql_select_db($dbname, $this->link_id) === false) {
         $this->ErrorMsg();
     }
     mysql_query("set names utf8;");
 }
Example #9
0
	function url($action = 'check') {
        $modules = '';
        $site = getcache('sitelist','commons');
        $sitename = $site['1']['name'];
		$siturl = $site['1']['domain'];
        foreach ($site as $list) $sitelist .= $list['domain'].',';
		$pars = array(
			'action'=>$action,
			'ZLCMS_username'=>'',
			'sitename'=>$sitename,
			'siteurl'=>$siturl,
			'charset'=>CHARSET,
			'version'=>PC_VERSION,
			'release'=>PC_RELEASE,
			'os'=>PHP_OS,
			'php'=>phpversion(),
			'mysql'=>mysql_get_server_info(),
			'browser'=>urlencode($_SERVER['HTTP_USER_AGENT']),
			'username'=>urlencode(param::get_cookie('admin_username')),
			'email'=> urlencode(param::get_cookie('admin_email')),
			'modules'=>ROUTE_M,
			'sitelist'=>urlencode($sitelist),
			'uuid'=>urlencode($this->uuid),
			);
		$data = http_build_query($pars);
		$verify = md5($this->uuid);		
		if($s = $this->module()) {
			$p = '&p='.$s;
		}
		return $this->update_url.'?'.$data.'&verify='.$verify.$p;
	}
Example #10
0
 function getDBVersion()
 {
     if (!$this->v('db_version')) {
         $this->db_version = preg_match("/^([0-9]+)\\.([0-9]+)\\.([0-9]+)/", mysql_get_server_info($this->getDBCon()), $m) ? sprintf("%02d-%02d-%02d", $m[1], $m[2], $m[3]) : '00-00-00';
     }
     return $this->db_version;
 }
 /**
  * Execute the script
  *
  * @param void
  * @return boolean
  */
 function execute()
 {
     // ---------------------------------------------------
     //  Check MySQL version
     // ---------------------------------------------------
     $mysql_version = mysql_get_server_info($this->database_connection);
     if ($mysql_version && version_compare($mysql_version, '4.1', '>=')) {
         $constants['DB_CHARSET'] = 'utf8';
         @mysql_query("SET NAMES 'utf8'", $this->database_connection);
         tpl_assign('default_collation', $default_collation = 'collate utf8_unicode_ci');
         tpl_assign('default_charset', $default_charset = 'DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
     } else {
         tpl_assign('default_collation', $default_collation = '');
         tpl_assign('default_charset', $default_charset = '');
     }
     // if
     tpl_assign('table_prefix', TABLE_PREFIX);
     // ---------------------------------------------------
     //  Execute migration
     // ---------------------------------------------------
     $total_queries = 0;
     $executed_queries = 0;
     $upgrade_script = tpl_fetch(get_template_path('db_migration/1_0_milanga'));
     if ($this->executeMultipleQueries($upgrade_script, $total_queries, $executed_queries, $this->database_connection)) {
         $this->printMessage("Database schema transformations executed (total queries: {$total_queries})");
     } else {
         $this->printMessage('Failed to execute DB schema transformations. MySQL said: ' . mysql_error(), true);
         return false;
     }
     // if
     $this->printMessage('Feng Office has been upgraded. You are now running Feng Office ' . $this->getVersionTo() . ' Enjoy!');
 }
 public function welcome()
 {
     /* 系统信息 */
     $conn = mysql_connect(C('DB_HOST'), C('DB_USER'), C('DB_PWD'));
     $gd = gd_version();
     $sys_info['os'] = PHP_OS;
     $sys_info['ip'] = $_SERVER['SERVER_ADDR'];
     $sys_info['web_server'] = $_SERVER['SERVER_SOFTWARE'];
     $sys_info['php_ver'] = PHP_VERSION;
     $sys_info['mysql_ver'] = mysql_get_server_info($conn);
     $sys_info['zlib'] = function_exists('gzclose') ? L('yes') : L('no');
     $sys_info['safe_mode'] = (boolean) ini_get('safe_mode') ? L('yes') : L('no');
     $sys_info['safe_mode_gid'] = (boolean) ini_get('safe_mode_gid') ? L('yes') : L('no');
     $sys_info['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : L('no_timezone');
     $sys_info['socket'] = function_exists('fsockopen') ? L('yes') : L('no');
     
     if ($gd == 0) {
         $sys_info['gd'] = 'N/A';
     } else {
         if ($gd == 1) {
             $sys_info['gd'] = 'GD1';
         } else {
             $sys_info['gd'] = 'GD2';
         }
         
         $sys_info['gd'] .= ' (';
         
         /* 检查系统支持的图片类型 */
         if ($gd && (imagetypes() & IMG_JPG) > 0) {
             $sys_info['gd'] .= ' JPEG';
         }
         
         if ($gd && (imagetypes() & IMG_GIF) > 0) {
             $sys_info['gd'] .= ' GIF';
         }
         
         if ($gd && (imagetypes() & IMG_PNG) > 0) {
             $sys_info['gd'] .= ' PNG';
         }
         
         $sys_info['gd'] .= ')';
     }
     
     /* IP库版本 */
     $sys_info['ip_version'] = ecs_geoip('255.255.255.0');
     
     /* 允许上传的最大文件大小 */
     $sys_info['max_filesize'] = ini_get('upload_max_filesize');
     $this->assign('sys_info', $sys_info);
     
     $this->assign('ecs_version', VERSION);
     $this->assign('ecs_release', RELEASE);
     $this->assign('ecs_charset', strtoupper(EC_CHARSET));
     $this->assign('install_date', local_date(C('date_format'), C('install_date')));
     // 检测是否授权
     $data = array('appid' => ECTOUCH_AUTH_KEY);
     $empower = $this->cloud->data($data)->act('get.license');
     $this->assign('empower', $empower);
     $this->display('welcome');
 }
Example #13
0
 function DB()
 {
     global $txpcfg;
     $this->host = $txpcfg['host'];
     $this->db = $txpcfg['db'];
     $this->user = $txpcfg['user'];
     $this->pass = $txpcfg['pass'];
     $this->client_flags = isset($txpcfg['client_flags']) ? $txpcfg['client_flags'] : 0;
     $this->link = @mysql_connect($this->host, $this->user, $this->pass, false, $this->client_flags);
     if (!$this->link) {
         die(db_down());
     }
     $this->version = mysql_get_server_info();
     if (!$this->link) {
         $GLOBALS['connected'] = false;
     } else {
         $GLOBALS['connected'] = true;
     }
     @mysql_select_db($this->db) or die(db_down());
     $version = $this->version;
     // be backwardscompatible
     if (isset($txpcfg['dbcharset']) && (intval($version[0]) >= 5 || preg_match('#^4\\.[1-9]#', $version))) {
         mysql_query("SET NAMES " . $txpcfg['dbcharset']);
     }
 }
Example #14
0
 protected function createTable()
 {
     $sql = file_get_contents(dirname(__FILE__) . '/sae.sql');
     $tablepre = C('DB_PREFIX');
     $tablesuf = C('DB_SUFFIX');
     $dbcharset = C('DB_CHARSET');
     $sql = str_replace("\r", "\n", $sql);
     $ret = array();
     $num = 0;
     foreach (explode(";\n", trim($sql)) as $query) {
         $queries = explode("\n", trim($query));
         foreach ($queries as $query) {
             $ret[$num] .= $query[0] == '#' || $query[0] . $query[1] == '--' ? '' : $query;
         }
         $num++;
     }
     unset($sql);
     foreach ($ret as $query) {
         $query = trim($query);
         if ($query) {
             if (substr($query, 0, 12) == 'CREATE TABLE') {
                 $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
                 $type = strtoupper(preg_replace("/^\\s*CREATE TABLE\\s+.+\\s+\\(.+?\\).*(ENGINE|TYPE)\\s*=\\s*([a-z]+?).*\$/isU", "\\2", $query));
                 $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
                 $query = preg_replace("/^\\s*(CREATE TABLE\\s+.+\\s+\\(.+?\\)).*\$/isU", "\\1", $query) . (mysql_get_server_info() > '4.1' ? " ENGINE={$type} DEFAULT CHARSET={$dbcharset}" : " TYPE={$type}");
             }
             self::$db->runSql($query);
         }
     }
 }
Example #15
0
 function dumper()
 {
     $this->SET['comp_method'] = '';
     $this->SET['comp_level'] = 5;
     $this->backup_file = $this->restore_file = '';
     $this->comp_methods = array();
     // Версия MySQL вида 40101
     preg_match("/^(\\d+)\\.(\\d+)\\.(\\d+)/", mysql_get_server_info(), $m);
     $this->mysql_version = sprintf("%d%02d%02d", $m[1], $m[2], $m[3]);
     $this->only_create = explode(',', ONLY_CREATE);
     $this->forced_charset = false;
     $this->restore_charset = $this->restore_collate = '';
     if (preg_match("/^(forced->)?(([a-z0-9]+)(\\_\\w+)?)\$/", RESTORE_CHARSET, $matches)) {
         $this->forced_charset = $matches[1] == 'forced->';
         $this->restore_charset = $matches[3];
         $this->restore_collate = !empty($matches[4]) ? ' COLLATE ' . $matches[2] : '';
     }
     $this->comp_methods[] = array('id' => '0', 'text' => TEXT_INFO_USE_NO_COMPRESSION);
     if (function_exists("gzopen")) {
         $this->comp_methods[] = array('id' => 'gz', 'text' => TEXT_INFO_USE_GZIP);
     }
     if (function_exists("bzopen")) {
         $this->comp_methods[] = array('id' => 'bz2', 'text' => TEXT_INFO_USE_BZIP2);
     }
 }
Example #16
0
 public function index()
 {
     //服务器信息
     $info = array('操作系统' => PHP_OS, '运行环境' => $_SERVER["SERVER_SOFTWARE"], 'PHP运行方式' => php_sapi_name(), 'MYSQL版本' => mysql_get_server_info(), '上传附件限制' => ini_get('upload_max_filesize'), '执行时间限制' => ini_get('max_execution_time') . "秒", '剩余空间' => round(@disk_free_space(".") / (1024 * 1024), 2) . 'M');
     $this->assign('server_info', $info);
     $this->display();
 }
Example #17
0
 /**
 +----------------------------------------------------------
 * 连接数据库方法
 +----------------------------------------------------------
 * @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);
     }
 }
Example #18
0
 /**
  * @param 	string $type The MySQL type, client or server
  * @return 	string The MySQL version of either the server or the client
  *
  * Function to retrieve the MySQL version (client/server)
  */
 public function mysql_acceptable($type = 'server')
 {
     // Server version
     if ($type == 'server') {
         // Retrieve the database settings from the session
         $server = $this->ci->session->userdata('hostname') . ':' . $this->ci->session->userdata('port');
         $username = $this->ci->session->userdata('username');
         $password = $this->ci->session->userdata('password');
         // Connect to MySQL
         if ($db = @mysql_connect($server, $username, $password)) {
             $this->mysql_server_version = @mysql_get_server_info($db);
             // Close the connection
             @mysql_close($db);
             // If the MySQL server version is at least version 5 return TRUE, else FALSE
             return $this->mysql_server_version >= 5 ? TRUE : FALSE;
         } else {
             @mysql_close($db);
             return FALSE;
         }
     } else {
         // Get the version
         $this->mysql_client_version = preg_replace('/[^0-9\\.]/', '', mysql_get_client_info());
         // If the MySQL client version is at least version 5 return TRUE, else FALSE
         return $this->mysql_client_version >= 5 ? TRUE : FALSE;
     }
 }
Example #19
0
 function connectMySQL()
 {
     try {
         $conexion = mysql_connect($this->host, $this->username, $this->password);
         //Establece la conexión con el servidor
         if ($conexion) {
             echo 'Conexion exitosa.';
             echo "<br>Info: ";
             echo "<br>Host: ";
             echo mysql_get_host_info();
             echo "<br>Server: ";
             echo mysql_get_server_info();
         } else {
             die('<br>Imposible conectar: ' . mysql_error());
         }
         $db = mysql_select_db($this->nameDB, $conexion);
         //Establece la conexión con una base de datos del servidor
     } catch (Exception $e) {
         echo "Error, falló la conexión con la base de datos";
         echo $e->getMessage();
         //Devuelve el mensaje de la exception
         echo $e->getCode();
         //Devuelve el código de la Execption(Integer)
         echo $e->getLine();
         //Devuelve la línea donde se lanzó la execption
     }
 }
Example #20
0
 /**
  * Clean orphan objects against linked objects
  *
  * @param     string    $table_link     table of linked object for JOIN; deprecated, for backward compat
  * @param     string    $field_link     field of linked object for JOIN; deprecated, for backward compat
  * @param     string    $field_object   field of current object for JOIN; deprecated, for backward compat
  * @return     bool    true on success
  */
 function cleanOrphan($table_link = "", $field_link = "", $field_object = "")
 {
     if (!empty($table_link)) {
         $this->handler->table_link = $table_link;
     }
     if (!empty($field_link)) {
         $this->handler->field_link = $field_link;
     }
     if (!empty($field_object)) {
         $this->handler->field_object = $field_object;
     }
     if (empty($this->handler->field_object) || empty($this->handler->table_link) || empty($this->handler->field_link)) {
         trigger_error("The link information is not set for '" . get_class($this->handler) . "' yet.", E_USER_WARNING);
         return null;
     }
     /* for MySQL 4.1+ */
     if (version_compare(mysql_get_server_info(), "4.1.0", "ge")) {
         $sql = "   DELETE FROM `{$this->handler->table}`" . "   WHERE (`{$this->handler->field_object}` NOT IN ( SELECT DISTINCT `{$this->handler->field_link}` FROM `{$this->handler->table_link}`) )";
     } else {
         // for 4.0+
         $sql = "   DELETE `{$this->handler->table}` FROM `{$this->handler->table}`" . "   LEFT JOIN `{$this->handler->table_link}` AS aa ON `{$this->handler->table}`.`{$this->handler->field_object}` = aa.`{$this->handler->field_link}`" . "   WHERE (aa.`{$this->handler->field_link}` IS NULL)";
     }
     if (!($result = $this->handler->db->queryF($sql))) {
         return false;
     }
     return true;
 }
Example #21
0
 /**
  * DB Connect
  * this method is private
  * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
  * @return resource
  */
 function __connect($connection)
 {
     // Ignore if no DB information exists
     if (strpos($connection['host'], ':') === false && $connection['port']) {
         $connection['host'] .= ':' . $connection['port'];
     }
     // Attempt to connect
     $result = @mysql_connect($connection['host'], $connection['user'], $connection['pass']);
     if (!$result) {
         exit('Unable to connect to DB.');
     }
     if (mysql_error()) {
         $this->setError(mysql_errno(), mysql_error());
         return;
     }
     // Error appears if the version is lower than 4.1.13
     if (version_compare(mysql_get_server_info($result), '4.1.13', '<')) {
         $this->setError(-1, 'Rhymix requires MySQL 4.1.13 or later. Current MySQL version is ' . mysql_get_server_info());
         return;
     }
     // Set charset
     $this->charset = isset($connection['charset']) ? $connection['charset'] : 'utf8';
     mysql_set_charset($this->charset, $result);
     // select db
     @mysql_select_db($connection['database'], $result);
     if (mysql_error()) {
         $this->setError(mysql_errno(), mysql_error());
         return;
     }
     return $result;
 }
Example #22
0
function createtable($sql, $db_charset)
{
    $db_charset = strpos($db_charset, '-') === FALSE ? $db_charset : str_replace('-', '', $db_charset);
    $type = strtoupper(preg_replace("/^\\s*CREATE TABLE\\s+.+\\s+\\(.+?\\).*(ENGINE|TYPE)\\s*=\\s*([a-z]+?).*\$/isU", "\\2", $sql));
    $type = in_array($type, array("MYISAM", "HEAP")) ? $type : "MYISAM";
    return preg_replace("/^\\s*(CREATE TABLE\\s+.+\\s+\\(.+?\\)).*\$/isU", "\\1", $sql) . (mysql_get_server_info() > "4.1" ? " ENGINE={$type} DEFAULT CHARSET={$db_charset}" : " TYPE={$type}");
}
Example #23
0
/**
 * 执行SQL文件
 * @param string  $file 要执行的sql文件路径
 * @param boolean $stop 遇错是否停止  默认为true
 * @param string  $db_charset 数据库编码 默认为utf-8
 * @return array
 */
function exec_sql_file($file, $stop = true, $db_charset = 'utf-8')
{
    if (!is_readable($file)) {
        $error = array('error_code' => 'SQL文件不可读', 'error_sql' => '');
        return $error;
    }
    $fp = fopen($file, 'rb');
    $sql = fread($fp, filesize($file));
    fclose($fp);
    $prefix = C('DB_PREFIX');
    //$sql = str_replace("\r", "\n", str_replace('`'.'ts_', '`'.M('')->tablePrefix, $sql));
    $sql = str_replace("\r", "\n", str_replace('`' . '__PREFIX__', '`' . $prefix, $sql));
    foreach (explode(";\n", trim($sql)) as $query) {
        $query = trim($query);
        if ($query) {
            if (substr($query, 0, 12) == 'CREATE TABLE') {
                //预处理建表语句
                $db_charset = strpos($db_charset, '-') === FALSE ? $db_charset : str_replace('-', '', $db_charset);
                $type = strtoupper(preg_replace("/^\\s*CREATE TABLE\\s+.+\\s+\\(.+?\\).*(ENGINE|TYPE)\\s*=\\s*([a-z]+?).*\$/isU", "\\2", $query));
                $type = in_array($type, array("MYISAM", "HEAP")) ? $type : "MYISAM";
                $_temp_query = preg_replace("/^\\s*(CREATE TABLE\\s+.+\\s+\\(.+?\\)).*\$/isU", "\\1", $query) . (mysql_get_server_info() > "4.1" ? " ENGINE={$type} DEFAULT CHARSET={$db_charset}" : " TYPE={$type}");
                $res = M('')->execute($_temp_query);
            } else {
                $res = M('')->execute($query);
            }
            if ($res === false) {
                $error[] = array('error_code' => M('')->getDbError(), 'error_sql' => $query);
                if ($stop) {
                    return $error[0];
                }
            }
        }
    }
    return $error;
}
 public function index()
 {
     //服务器信息
     $info = array('操作系统' => PHP_OS, '运行环境' => $_SERVER["SERVER_SOFTWARE"], 'PHP运行方式' => php_sapi_name(), 'MYSQL版本' => mysql_get_server_info(), '85ZU版本' => ZU_VERSION . "&nbsp;&nbsp;&nbsp; [<a href='http://www.85zu.com' target='_blank'>访问官网</a>]", '上传附件限制' => ini_get('upload_max_filesize'), '执行时间限制' => ini_get('max_execution_time') . "秒", '剩余空间' => round(@disk_free_space(".") / (1024 * 1024 * 1024), 2) . 'G');
     $this->assign('server_info', $info);
     $this->display();
 }
Example #25
0
function createtable($sql, $db_charset)
{
    $db_charset = strpos($db_charset, '-') === false ? $db_charset : str_replace('-', '', $db_charset);
    $type = strtoupper(preg_replace("/^\\s*CREATE TABLE\\s+.+\\s+\\(.+?\\).*(ENGINE|TYPE)\\s*=\\s*([a-z]+?).*\$/isU", '\\2', $sql));
    $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
    return preg_replace("/^\\s*(CREATE TABLE\\s+.+\\s+\\(.+?\\)).*\$/isU", '\\1', $sql) . (mysql_get_server_info() > '4.1' ? " ENGINE={$type} DEFAULT CHARSET={$db_charset}" : " TYPE={$type}");
}
Example #26
0
 function version()
 {
     if (empty($this->version)) {
         $this->version = mysql_get_server_info($this->link);
     }
     return $this->version;
 }
Example #27
0
 /**
 +----------------------------------------------------------
 * 连接数据库方法
 +----------------------------------------------------------
 * @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];
 }
Example #28
0
function txp_validate($user, $password, $log = TRUE)
{
    $safe_user = doSlash($user);
    $name = FALSE;
    $hash = safe_field('pass', 'txp_users', "name = '{$safe_user}'");
    $phpass = new PasswordHash(PASSWORD_COMPLEXITY, PASSWORD_PORTABILITY);
    // check post-4.3-style passwords
    if ($phpass->CheckPassword($password, $hash)) {
        if ($log) {
            $name = safe_field("name", "txp_users", "name = '{$safe_user}' and privs > 0");
        } else {
            $name = $user;
        }
    } else {
        // no good password: check 4.3-style passwords
        $passwords = array();
        $passwords[] = "password(lower('" . doSlash($password) . "'))";
        $passwords[] = "password('" . doSlash($password) . "')";
        if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
            $passwords[] = "old_password(lower('" . doSlash($password) . "'))";
            $passwords[] = "old_password('" . doSlash($password) . "')";
        }
        $name = safe_field("name", "txp_users", "name = '{$safe_user}' and (pass = "******") and privs > 0");
        // old password is good: migrate password to phpass
        if ($name !== FALSE) {
            safe_update("txp_users", "pass = '******'", "name = '{$safe_user}'");
        }
    }
    if ($name !== FALSE && $log) {
        // update the last access time
        safe_update("txp_users", "last_access = now()", "name = '{$safe_user}'");
    }
    return $name;
}
Example #29
0
 /**
 +----------------------------------------------------------
 * 连接数据库方法
 +----------------------------------------------------------
 * @access public 
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $conn = $this->pconnect ? 'mysql_pconnect' : 'mysql_connect';
         $this->linkID[$linkNum] = $conn($config['hostname'] . ':' . $config['hostport'], $config['username'], $config['password']);
         if (!$this->linkID[$linkNum]) {
             throw_exception(mysql_error());
             return False;
         }
         if (!mysql_select_db($config['database'], $this->linkID[$linkNum])) {
             throw_exception($this->error());
             return False;
         }
         $this->dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         if ($this->dbVersion >= "4.1") {
             //使用UTF8存取数据库 需要mysql 4.1.0以上支持
             mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]);
         }
         // 标记连接成功
         $this->connected = true;
         // 注销数据库连接配置信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
Example #30
0
 private function connect()
 {
     $this->link_id = @mysql_connect($this->settings['dbhost'], $this->settings['dbuser'], $this->settings['dbpw'], true);
     //非持久连接
     if (!$this->link_id) {
         if (!$this->settings['quiet']) {
             $this->ErrorMsg("Can't Connect MySQL Server({$dbhost})!");
         }
         return false;
     }
     $this->version = mysql_get_server_info($this->link_id);
     mysql_query("\n            SET character_set_connection={$this->settings['charset']},\n            character_set_results={$this->settings['charset']},\n            character_set_client=binary", $this->link_id);
     mysql_query("SET sql_mode=''", $this->link_id);
     $this->starttime = microtime(true);
     //time();
     /* 选择数据库 */
     if ($this->settings['dbname']) {
         if (mysql_select_db($this->settings['dbname'], $this->link_id) === false) {
             if (!$this->settings['quiet']) {
                 $this->ErrorMsg("Can't select MySQL database({$this->settings['dbname']})!");
             }
             return false;
         } else {
             return true;
         }
     } else {
         return true;
     }
 }