ecshop适应在PHP7的修改方法解决报错的实现
下面小编就为大家带来一篇ecshop适应在PHP7的修改方法解决报错的实现。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
ecshop这个系统,到目前也没见怎么推出新版本,如果是新项目,不太建议使用它。不过,因为我一直以来都在使用中,所以不得不更改让其适应PHP新版本。现在PHP7已经出发行版了,所以更改来继续使用吧。具体的更改有以下方面:
(1)将mysql扩展的使用替换掉,改为使用mysqli或pdo:
从php5.5开始,mysql扩展将废弃了。
具体更改的文件在于includes/cls_mysql.php。这是个不小的工程,文件代码太长……
if(!defined(''DITAN_ECS''))
{
die(''Hackingattempt'');
}
classcls_mysql
{
var$link_id=NULL;
var$settings=array();
var$queryCount=0;
var$queryTime='''';
var$queryLog=array();
var$max_cache_time=300;//最大的缓存时间,以秒为单位
var$cache_data_dir=''temp/query_caches/'';
var$root_path='''';
var$error_message=array();
var$platform='''';
var$version='''';
var$dbhash='''';
var$starttime=0;
var$timeline=0;
var$timezone=0;
//事务指令数
protected$transTimes=0;
var$mysql_config_cache_file_time=0;
var$mysql_disable_cache_tables=array();//不允许被缓存的表,遇到将不会进行缓存
function__construct($dbhost,$dbuser,$dbpw,$dbname='''',$charset=''gbk'',$pconnect=0,$quiet=0)
{
$this->cls_mysql($dbhost,$dbuser,$dbpw,$dbname,$charset,$pconnect,$quiet);
}
functioncls_mysql($dbhost,$dbuser,$dbpw,$dbname='''',$charset=''gbk'',$pconnect=0,$quiet=0)
{
if(defined(''EC_CHARSET''))
{
$charset=strtolower(str_replace(''-'','''',EC_CHARSET));
}
if(defined(''ROOT_PATH'')&&!$this->root_path)
{
$this->root_path=ROOT_PATH;
}
if($quiet)
{
$this->connect($dbhost,$dbuser,$dbpw,$dbname,$charset,$pconnect,$quiet);
}
else
{
$this->settings=array(
''dbhost''=>$dbhost,
''dbuser''=>$dbuser,
''dbpw''=>$dbpw,
''dbname''=>$dbname,
''charset''=>$charset,
''pconnect''=>$pconnect
);
}
}
functionconnect($dbhost,$dbuser,$dbpw,$dbname='''',$charset=''utf8'',$pconnect=0,$quiet=0)
{
if($pconnect)
{
$this->link_id=newmysqli(''p:''.$dbhost,$dbuser,$dbpw);
if($this->link_id->connect_error)
{
if(!$quiet)
{
$this->ErrorMsg("Can''tpConnectMySQLServer($dbhost)!");
}
returnfalse;
}
}
else
{
$this->link_id=newmysqli($dbhost,$dbuser,$dbpw);
if($this->link_id->connect_error)
{
if(!$quiet)
{
$this->ErrorMsg("Can''tConnectMySQLServer($dbhost)!");
}
returnfalse;
}
}
$this->dbhash=md5($this->root_path.$dbhost.$dbuser.$dbpw.$dbname);
$this->version=$this->link_id->server_version;
/对字符集进行初始化/
$this->link_id->set_charset($charset);
$this->link_id->query("SETsql_mode=''''");
$sqlcache_config_file=$this->root_path.$this->cache_data_dir.''sqlcache_config_file_''.$this->dbhash.''.php'';
@include($sqlcache_config_file);
$this->starttime=time();
if($this->max_cache_time&&$this->starttime>$this->mysql_config_cache_file_time+$this->max_cache_time)
{
if($dbhost!=''.'')
{
$result=$this->link_id->query("SHOWVARIABLESLIKE''basedir''");
$row=$result->fetch_array(MYSQLI_ASSOC);
$result->free();
if(!empty($row[''Value'']{1})&&$row[''Value'']{1}=='':''&&!empty($row[''Value'']{2})&&$row[''Value'']{2}=="/")
{
$this->platform=''WINDOWS'';
}
else
{
$this->platform=''OTHER'';
}
}
else
{
$this->platform=''WINDOWS'';
}
if($this->platform==''OTHER''&&
($dbhost!=''.''&&strtolower($dbhost)!=''localhost:3306''&&$dbhost!=''127.0.0.1:3306'')||
date_default_timezone_get()==''UTC'')
{
$result=$this->link_id->query("SELECTUNIX_TIMESTAMP()AStimeline,UNIX_TIMESTAMP(''".date(''Y-m-dH:i:s'',$this->starttime)."'')AStimezone");
$row=$result->fetch_array(MYSQLI_ASSOC);
$result->free();
if($dbhost!=''.''&&strtolower($dbhost)!=''localhost:3306''&&$dbhost!=''127.0.0.1:3306'')
{
$this->timeline=$this->starttime-$row[''timeline''];
}
if(date_default_timezone_get()==''UTC'')
{
$this->timezone=$this->starttime-$row[''timezone''];
}
}
$content=''<''."?php\r\n".
''$this->mysql_config_cache_file_time=''.$this->starttime.";\r\n".
''$this->timeline=''.$this->timeline.";\r\n".
''$this->timezone=''.$this->timezone.";\r\n".
''$this->platform=''."''".$this->platform."'';\r\n?".''>'';
@file_put_contents($sqlcache_config_file,$content);
}
/选择数据库/
if($dbname)
{
if($this->link_id->select_db($dbname)===false)
{
if(!$quiet)
{
$this->ErrorMsg("Can''tselectMySQLdatabase($dbname)!");
}
returnfalse;
}
else
{
returntrue;
}
}
else
{
returntrue;
}
}
functionselect_database($dbname)
{
return$this->link_id->select_db($dbname);
}
functionset_mysql_charset($charset)
{
if(in_array(strtolower($charset),array(''gbk'',''big5'',''utf-8'',''utf8'')))
{
$charset=str_replace(''-'','''',$charset);
}
$this->link_id->set_charset($charset);
}
functionfetch_array($query,$result_type=MYSQLI_ASSOC)
{
$row=$query->fetch_array($result_type);
$query->free();
return$row;
}
functionquery($sql,$type='''')
{
if($this->link_id===NULL)
{
$this->connect($this->settings[''dbhost''],$this->settings[''dbuser''],$this->settings[''dbpw''],$this->settings[''dbname''],$this->settings[''charset''],$this->settings[''pconnect'']);
$this->settingswww.baiyuewang.net=array();
}
if($this->queryCount++<=99)
{
$this->queryLog[]=$sql;
}
if($this->queryTime=='''')
{
if(PHP_VERSION>=''5.0.0'')
{
$this->queryTime=microtime(true);
}
else
{
$this->queryTime=microtime();
}
}
/当当前的时间大于类初始化时间的时候,自动执行ping这个自动重新连接操作/
if(time()>$this->starttime+1)
{
$this->link_id->ping();
}
if(!($query=$this->link_id->query($sql))&&$type!=''SILENT'')
{
$this->error_message[][''message'']=''MySQLQueryError'';
$this->error_messagewww.wang027.com[][''sql'']=$sql;
$this->error_message[][''error'']=$this->link_id->error;
$this->error_message[][''errno'']=$this->link_id->errno;
$this->ErrorMsg();
returnfalse;
}
if(defined(''DEBUG_MODE'')&&(DEBUG_MODE&8)==8)
{
$logfilename=$this->root_path.DATA_DIR.''/mysql_query_''.$this->dbhash.''_''.date(''Y_m_d'').''.log'';
$str=$sql."\n\n";
if(PHP_VERSION>=''5.0'')
{
file_put_contents($logfilename,$str,FILE_APPEND);
}
else
{
$fp=@fopen($logfilename,''ab+'');
if($fp)
{
fwrite($fp,$str);
fclose($fp);
}
}
}
return$query;
}
functionaffected_rows()
{
return$this->link_id->affected_rows;
}
functionerror()
{
return$this->link_id->error;
}
functionerrno()
{
return$this->link_id->errno;
}
functionresult($query,$row)
{
$query->data_seek($row);
$result=$query->fetch_row();
$query->free();
return$result;
}
functionnum_rows($query)
{
return$query->num_rows;
}
functionnum_fields($query)
{
return$this->link_id->field_count;
}
functionfree_result($query)
{
return$query->free();
}
functioninsert_id()
{
return$this->link_id->insert_id;
}
functionfetchRow($query)
{
return$query->fetch_assoc();
}
functionfetch_fields($query)
{
return$query->fetch_field();
}
functionversion()
{
return$this->version;
}
functionping()
{
return$this->link_id->ping();
}
functionescape_string($unescaped_string)
{
return$this->link_id->real_escape_string($unescaped_string);
}
functionclose()
{
return$this->link_id->close();
}
functionErrorMsg($message='''',$sql='''')
{
if($message)
{
echo"DTXBinfo:$message\n\n
";
//print(''http://faq.comsenz.com/'');
}
else
{
echo"MySQLservererrorreport:";
print_r($this->error_message);
//echo"
error_message[3][''errno'']."&dberror=".urlencode($this->error_message[2][''error''])."''target=''_blank''>http://faq.comsenz.com/";
}
exit;
}
/仿真Adodb函数/
functionselectLimit($sql,$num,$start=0)
{
if($start==0)
{
$sql.=''LIMIT''.$num;
}
else
{
$sql.=''LIMIT''.$start.'',''.$num;
}
return$this->query($sql);
}
functiongetOne($sql,$limited=false)
{
if($limited==true)
{
$sql=trim($sql.''LIMIT1'');
}
$res=$this->query($sql);
if($res!==false)
{
$row=$res->fetch_row();
$res->free();
if($row!==false)
{
return$row[0];
}
else
{
return'''';
}
}
else
{
returnfalse;
}
}
functiongetOneCached($sql,$cached=''FILEFIRST'')
{
$sql=trim($sql.''LIMIT1'');
$cachefirst=($cached==''FILEFIRST''||($cached==''MYSQLFIRST''&&$this->platform!=''WINDOWS''))&&$this->max_cache_time;
if(!$cachefirst)
{
return$this->getOne($sql,true);
}
else
{
$result=$this->getSqlCacheData($sql,$cached);
if(empty($result[''storecache''])==true)
{
return$result[''data''];
}
}
$arr=$this->getOne($sql,true);
if($arr!==false&&$cachefirst)
{
$this->setSqlCacheData($result,$arr);
}
return$arr;
}
functiongetAll($sql)
{
$res=$this->query($sql);
if($res!==false)
{
$arr=$res->fetch_all(MYSQLI_ASSOC);
$res->free();
return$arr;
}
else
{
returnfalse;
}
}
functiongetAllCached($sql,$cached=''FILEFIRST'')
{
$cachefirst=($cached==''FILEFIRST''||($cached==''MYSQLFIRST''&&$this->platform!=''WINDOWS''))&&$this->max_cache_time;
if(!$cachefirst)
{
return$this->getAll($sql);
}
else
{
$result=$this->getSqlCacheData
|
|