Commit 62a76ef8 authored by nahakyuu's avatar nahakyuu

fix version compare

```
'10.5.5-MariaDB-1:10.5.5+maria~focal' < '5.3.0' == true'
```
and more
parent fa038d00
......@@ -6,7 +6,7 @@ define('IN_GAME', TRUE);
define('GAME_ROOT', dirname(__FILE__));
define('GAMENAME', 'bra');
if(PHP_VERSION < '4.3.0') {
if(version_compare(PHP_VERSION, '4.3.0', '<')) {
exit('PHP version must >= 4.3.0!');
}
require GAME_ROOT.'/include/global.func.php';
......
......@@ -6,7 +6,7 @@ define('IN_GAME', TRUE);
define('GAME_ROOT', dirname(__FILE__));
define('GAMENAME', 'bra');
if(PHP_VERSION < '4.3.0') {
if(version_compare(PHP_VERSION, '4.3.0', '<')) {
exit('PHP version must >= 4.3.0!');
}
require GAME_ROOT.'./include/global.func.php';
......
......@@ -6,7 +6,7 @@ define('IN_GAME', TRUE);
define('GAME_ROOT', substr(dirname(__FILE__), 0, -7));
define('GAMENAME', 'bra');
if(PHP_VERSION < '4.3.0') {
if(version_compare(PHP_VERSION, '4.3.0', '<')) {
exit('PHP version must >= 4.3.0!');
}
require GAME_ROOT.'./include/global.func.php';
......
......@@ -22,7 +22,7 @@ class dbstuff {
}
}
if ($this->version () > '4.1') {
if(version_compare($this->version (), '4.1', '>')) {
global $charset, $dbcharset;
if (! $dbcharset && in_array ( strtolower ( $charset ), array ('gbk', 'big5', 'utf-8' ) )) {
$dbcharset = str_replace ( '-', '', $charset );
......@@ -32,7 +32,7 @@ class dbstuff {
mysql_query ( "SET character_set_connection=$dbcharset, character_set_results=$dbcharset, character_set_client=$dbcharset" );
}
if ($this->version () > '5.0.1') {
if(version_compare($this->version (), '5.0.1', '>')) {
mysql_query ( "SET sql_mode=''" );
}
}
......
......@@ -183,7 +183,7 @@ function openfile($filename){
}
function compatible_json_encode($data){ //自动选择使用内置函数或者自定义函数,结合JSON.php可做到兼容低版本PHP
if(PHP_VERSION < '5.2.0'){
if(version_compare(PHP_VERSION, '5.2.0', '<')) {
require_once GAME_ROOT.'./include/JSON.php';
$json = new Services_JSON();
$jdata = $json->encode($data);
......
......@@ -7,7 +7,7 @@ error_reporting(E_ERROR | E_WARNING | E_PARSE);
define('IN_GAME', TRUE);
define('GAME_ROOT', '');
if(PHP_VERSION < '4.3.0') {
if(version_compare(PHP_VERSION, '4.3.0', '<')) {
exit('PHP version must >= 4.3.0!');
}
......@@ -657,7 +657,7 @@ if(!$action) {
$curr_os = PHP_OS;
$curr_php_version = PHP_VERSION;
if($curr_php_version < '4.3.0') {
if(version_compare($curr_php_version, '4.3.0', '<')) {
$msg .= "<font color=\"#FF0000\">$lang[php_version_430]</font>\t";
$quit = TRUE;
}
......@@ -673,7 +673,7 @@ if(!$action) {
$query = $db->query("SELECT VERSION()");
$curr_mysql_version = $db->result($query, 0);
if($curr_mysql_version < '3.23') {
if(version_compare($curr_mysql_version, '3.23', '<')) {
$msg .= "<font color=\"#FF0000\">$lang[mysql_version_323]</font>\t";
$quit = TRUE;
}
......@@ -701,7 +701,7 @@ if(!$action) {
$db->select_db($dbname);
if($db->error()) {
if($db->version() > '4.1') {
if(version_compare($db->version(), '3.23', '<')) {
$db->query("CREATE DATABASE IF NOT EXISTS $dbname DEFAULT CHARACTER SET $dbcharset");
} else {
$db->query("CREATE DATABASE IF NOT EXISTS $dbname");
......@@ -1231,7 +1231,7 @@ function runquery($sql) {
if(substr($query, 0, 12) == 'CREATE TABLE') {
$name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
echo $lang['create_table'].' '.$name.' ... <font color="#0000EE">'.$lang['succeed'].'</font><br>';
$db->query(createtable($query, $dbcharset));
$db->query(createtable($db, $query, $dbcharset));
} else {
$db->query($query);
}
......@@ -1299,11 +1299,11 @@ function random($length) {
return $hash;
}
function createtable($sql, $dbcharset) {
function createtable($db, $sql, $dbcharset) {
$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=$dbcharset" : " TYPE=$type");
(version_compare($db->version(), '4.1', '>') ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
}
function setconfig($string) {
......
......@@ -7,7 +7,7 @@ $now = time();
define('IN_GAME', TRUE);
define('GAME_ROOT', substr(dirname(__FILE__), 0, 0));
define('GAMENAME', 'bra');
if(PHP_VERSION < '4.3.0') {
if(version_compare(PHP_VERSION, '4.3.0', '<')) {
exit('PHP version must >= 4.3.0!');
}
require_once GAME_ROOT.'./include/global.func.php';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment