CMS 튜토리얼 ECShop ecshop에서 PHP7을 수정하고 지원하는 방법

ecshop에서 PHP7을 수정하고 지원하는 방법

Jul 11, 2020 am 09:54 AM
ecshop

ecshop修改php的方法:首先将mysql扩展的使用替换掉,改为使用mysqli或pdo;然后更改“cls_image.php”的“gd_version()”方法,将这个方法改为静态方法;最后去除使用类名的构造函数。

ecshop에서 PHP7을 수정하고 지원하는 방법

ecshop支持PHP7的修改方法

(1)将mysql扩展的使用替换掉,改为使用mysqli或pdo(推荐使用mysqli):

推荐:《ECShop教程

从php5.5开始,mysql扩展将废弃了。 具体更改的文件在于includes/cls_mysql.php。这是个不小的工程,文件代码太长……

if (!defined('DITAN_ECS'))
{
die('Hacking attempt');
}
class cls_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);
}
function cls_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
);
}
}
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'utf8', $pconnect = 0, $quiet = 0)
{
if ($pconnect)
{
$this->link_id = new mysqli('p:'.$dbhost, $dbuser, $dbpw);
if ($this->link_id->connect_error)
{
if (!$quiet)
{
$this->ErrorMsg("Can't pConnect MySQL Server($dbhost)!");
}
return false;
}
}
else
{
$this->link_id = new mysqli($dbhost, $dbuser, $dbpw);
if ($this->link_id->connect_error)
{
if (!$quiet)
{
$this->ErrorMsg("Can't Connect MySQL Server($dbhost)!");
}
return false;
}
}
$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("SET sql_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("SHOW VARIABLES LIKE '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("SELECT UNIX_TIMESTAMP() AS timeline, UNIX_TIMESTAMP('" . date('Y-m-d H:i:s', $this->starttime) . "') AS timezone");
$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 = &#39;<&#39; . "?php\r\n" .
&#39;$this->mysql_config_cache_file_time = &#39; . $this->starttime . ";\r\n" .
&#39;$this->timeline = &#39; . $this->timeline . ";\r\n" .
&#39;$this->timezone = &#39; . $this->timezone . ";\r\n" .
&#39;$this->platform = &#39; . "&#39;" . $this->platform . "&#39;;\r\n?" . &#39;>&#39;;
@file_put_contents($sqlcache_config_file, $content);
}
/* 选择数据库 */
if ($dbname)
{
if ($this->link_id->select_db($dbname) === false )
{
if (!$quiet)
{
$this->ErrorMsg("Can&#39;t select MySQL database($dbname)!");
}
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
function select_database($dbname)
{
return $this->link_id->select_db($dbname);
}
function set_mysql_charset($charset)
{
if (in_array(strtolower($charset), array(&#39;gbk&#39;, &#39;big5&#39;, &#39;utf-8&#39;, &#39;utf8&#39;)))
{
$charset = str_replace(&#39;-&#39;, &#39;&#39;, $charset);
}
$this->link_id->set_charset($charset);
}
function fetch_array($query, $result_type = MYSQLI_ASSOC)
{
$row = $query->fetch_array($result_type);
$query->free();
return $row;
}
function query($sql, $type = &#39;&#39;)
{
if ($this->link_id === NULL)
{
$this->connect($this->settings[&#39;dbhost&#39;], $this->settings[&#39;dbuser&#39;], $this->settings[&#39;dbpw&#39;], $this->settings[&#39;dbname&#39;], $this->settings[&#39;charset&#39;], $this->settings[&#39;pconnect&#39;]);
$this->settings = array();
}
if ($this->queryCount++ <= 99)
{
$this->queryLog[] = $sql;
}
if ($this->queryTime == &#39;&#39;)
{
if (PHP_VERSION >= &#39;5.0.0&#39;)
{
$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 != &#39;SILENT&#39;)
{
$this->error_message[][&#39;message&#39;] = &#39;MySQL Query Error&#39;;
$this->error_message[][&#39;sql&#39;] = $sql;
$this->error_message[][&#39;error&#39;] = $this->link_id->error;
$this->error_message[][&#39;errno&#39;] = $this->link_id->errno;
$this->ErrorMsg();
return false;
}
if (defined(&#39;DEBUG_MODE&#39;) && (DEBUG_MODE & 8) == 8)
{
$logfilename = $this->root_path . DATA_DIR . &#39;/mysql_query_&#39; . $this->dbhash . &#39;_&#39; . date(&#39;Y_m_d&#39;) . &#39;.log&#39;;
$str = $sql . "\n\n";
if (PHP_VERSION >= &#39;5.0&#39;)
{
file_put_contents($logfilename, $str, FILE_APPEND);
}
else
{
$fp = @fopen($logfilename, &#39;ab+&#39;);
if ($fp)
{
fwrite($fp, $str);
fclose($fp);
}
}
}
return $query;
}
function affected_rows()
{
return $this->link_id->affected_rows;
}
function error()
{
return $this->link_id->error;
}
function errno()
{
return $this->link_id->errno;
}
function result($query, $row)
{
$query->data_seek($row);
$result = $query->fetch_row();
$query->free();
return $result;
}
function num_rows($query)
{
return $query->num_rows;
}
function num_fields($query)
{
return $this->link_id->field_count;
}
function free_result($query)
{
return $query->free();
}
function insert_id()
{
return $this->link_id->insert_id;
}
function fetchRow($query)
{
return $query->fetch_assoc();
}
function fetch_fields($query)
{
return $query->fetch_field();
}
function version()
{
return $this->version;
}
function ping()
{
return $this->link_id->ping();
}
function escape_string($unescaped_string)
{
return $this->link_id->real_escape_string($unescaped_string);
}
function close()
{
return $this->link_id->close();
}
function ErrorMsg($message = &#39;&#39;, $sql = &#39;&#39;)
{
if ($message)
{
echo "DTXB info: $message\n\n
";
//print(&#39;http://faq.comsenz.com/&#39;);
}
else
{
echo "MySQL server error report:";
print_r($this->error_message);
//echo "
http://faq.comsenz.com/";
}
exit;
}
/* 仿真 Adodb 函数 */
function selectLimit($sql, $num, $start = 0)
{
if ($start == 0)
{
$sql .= &#39; LIMIT &#39; . $num;
}
else
{
$sql .= &#39; LIMIT &#39; . $start . &#39;, &#39; . $num;
}
return $this->query($sql);
}
function getOne($sql, $limited = false)
{
if ($limited == true)
{
$sql = trim($sql . &#39; LIMIT 1&#39;);
}
$res = $this->query($sql);
if ($res !== false)
{
$row = $res->fetch_row();
$res->free();
if ($row !== false)
{
return $row[0];
}
else
{
return &#39;&#39;;
}
}
else
{
return false;
}
}
function getOneCached($sql, $cached = &#39;FILEFIRST&#39;)
{
$sql = trim($sql . &#39; LIMIT 1&#39;);
$cachefirst = ($cached == &#39;FILEFIRST&#39; || ($cached == &#39;MYSQLFIRST&#39; && $this->platform != &#39;WINDOWS&#39;)) && $this->max_cache_time;
if (!$cachefirst)
{
return $this->getOne($sql, true);
}
else
{
$result = $this->getSqlCacheData($sql, $cached);
if (empty($result[&#39;storecache&#39;]) == true)
{
return $result[&#39;data&#39;];
}
}
$arr = $this->getOne($sql, true);
if ($arr !== false && $cachefirst)
{
$this->setSqlCacheData($result, $arr);
}
return $arr;
}
function getAll($sql)
{
$res = $this->query($sql);
if ($res !== false)
{
$arr = $res->fetch_all(MYSQLI_ASSOC);
$res->free();
return $arr;
}
else
{
return false;
}
}
function getAllCached($sql, $cached = &#39;FILEFIRST&#39;)
{
$cachefirst = ($cached == &#39;FILEFIRST&#39; || ($cached == &#39;MYSQLFIRST&#39; && $this->platform != &#39;WINDOWS&#39;)) && $this->max_cache_time;
if (!$cachefirst)
{
return $this->getAll($sql);
}
else
{
$result = $this->getSqlCacheData($sql, $cached);
if (empty($result[&#39;storecache&#39;]) == true)
{
return $result[&#39;data&#39;];
}
}
$arr = $this->getAll($sql);
if ($arr !== false && $cachefirst)
{
$this->setSqlCacheData($result, $arr);
}
return $arr;
}
function getRow($sql, $limited = false)
{
if ($limited == true)
{
$sql = trim($sql . &#39; LIMIT 1&#39;);
}
$res = $this->query($sql);
if ($res !== false)
{
$result = $res->fetch_assoc();
$res->free();
return $result;
}
else
{
return false;
}
}
function getRowCached($sql, $cached = &#39;FILEFIRST&#39;)
{
$cachefirst = ($cached == &#39;FILEFIRST&#39; || ($cached == &#39;MYSQLFIRST&#39; && $this->platform != &#39;WINDOWS&#39;)) && $this->max_cache_time;
if (!$cachefirst)
{
return $this->getRow($sql, true);
}
else
{
$result = $this->getSqlCacheData($sql, $cached);
if (empty($result[&#39;storecache&#39;]) == true)
{
return $result[&#39;data&#39;];
}
}
$arr = $this->getRow($sql, true);
if ($arr !== false && $cachefirst)
{
$this->setSqlCacheData($result, $arr);
}
return $arr;
}
function getCol($sql)
{
$res = $this->query($sql);
if ($res !== false)
{
$arr = array();
while ($row = $res->fetch_row())
{
$arr[] = $row[0];
}
$res->free();
return $arr;
}
else
{
return false;
}
}
function getColCached($sql, $cached = &#39;FILEFIRST&#39;)
{
$cachefirst = ($cached == &#39;FILEFIRST&#39; || ($cached == &#39;MYSQLFIRST&#39; && $this->platform != &#39;WINDOWS&#39;)) && $this->max_cache_time;
if (!$cachefirst)
{
return $this->getCol($sql);
}
else
{
$result = $this->getSqlCacheData($sql, $cached);
if (empty($result[&#39;storecache&#39;]) == true)
{
return $result[&#39;data&#39;];
}
}
$arr = $this->getCol($sql);
if ($arr !== false && $cachefirst)
{
$this->setSqlCacheData($result, $arr);
}
return $arr;
}
function autoExecute($table, $field_values, $mode = &#39;INSERT&#39;, $where = &#39;&#39;, $querymode = &#39;&#39;)
{
$field_names = $this->getCol(&#39;DESC &#39; . $table);
$sql = &#39;&#39;;
if ($mode == &#39;INSERT&#39;)
{
$fields = $values = array();
foreach ($field_names AS $value)
{
if (array_key_exists($value, $field_values) == true)
{
$fields[] = $value;
$values[] = "&#39;" . $field_values[$value] . "&#39;";
}
}
if (!empty($fields))
{
$sql = &#39;INSERT INTO &#39; . $table . &#39; (&#39; . implode(&#39;, &#39;, $fields) . &#39;) VALUES (&#39; . implode(&#39;, &#39;, $values) . &#39;)&#39;;
}
}
else
{
$sets = array();
foreach ($field_names AS $value)
{
if (array_key_exists($value, $field_values) == true)
{
$sets[] = $value . " = &#39;" . $field_values[$value] . "&#39;";
}
}
if (!empty($sets))
{
$sql = &#39;UPDATE &#39; . $table . &#39; SET &#39; . implode(&#39;, &#39;, $sets) . &#39; WHERE &#39; . $where;
}
}
if ($sql)
{
return $this->query($sql, $querymode);
}
else
{
return false;
}
}
function autoReplace($table, $field_values, $update_values, $where = &#39;&#39;, $querymode = &#39;&#39;)
{
$field_descs = $this->getAll(&#39;DESC &#39; . $table);
$primary_keys = array();
foreach ($field_descs AS $value)
{
$field_names[] = $value[&#39;Field&#39;];
if ($value[&#39;Key&#39;] == &#39;PRI&#39;)
{
$primary_keys[] = $value[&#39;Field&#39;];
}
}
$fields = $values = array();
foreach ($field_names AS $value)
{
if (array_key_exists($value, $field_values) == true)
{
$fields[] = $value;
$values[] = "&#39;" . $field_values[$value] . "&#39;";
}
}
$sets = array();
foreach ($update_values AS $key => $value)
{
if (array_key_exists($key, $field_values) == true)
{
if (is_int($value) || is_float($value))
{
$sets[] = $key . &#39; = &#39; . $key . &#39; + &#39; . $value;
}
else
{
$sets[] = $key . " = &#39;" . $value . "&#39;";
}
}
}
$sql = &#39;&#39;;
if (empty($primary_keys))
{
if (!empty($fields))
{
$sql = &#39;INSERT INTO &#39; . $table . &#39; (&#39; . implode(&#39;, &#39;, $fields) . &#39;) VALUES (&#39; . implode(&#39;, &#39;, $values) . &#39;)&#39;;
}
}
else
{
if ($this->version() >= &#39;4.1&#39;)
{
if (!empty($fields))
{
$sql = &#39;INSERT INTO &#39; . $table . &#39; (&#39; . implode(&#39;, &#39;, $fields) . &#39;) VALUES (&#39; . implode(&#39;, &#39;, $values) . &#39;)&#39;;
if (!empty($sets))
{
$sql .= &#39;ON DUPLICATE KEY UPDATE &#39; . implode(&#39;, &#39;, $sets);
}
}
}
else
{
if (empty($where))
{
$where = array();
foreach ($primary_keys AS $value)
{
if (is_numeric($value))
{
$where[] = $value . &#39; = &#39; . $field_values[$value];
}
else
{
$where[] = $value . " = &#39;" . $field_values[$value] . "&#39;";
}
}
$where = implode(&#39; AND &#39;, $where);
}
if ($where && (!empty($sets) || !empty($fields)))
{
if (intval($this->getOne("SELECT COUNT(*) FROM $table WHERE $where")) > 0)
{
if (!empty($sets))
{
$sql = &#39;UPDATE &#39; . $table . &#39; SET &#39; . implode(&#39;, &#39;, $sets) . &#39; WHERE &#39; . $where;
}
}
else
{
if (!empty($fields))
{
$sql = &#39;REPLACE INTO &#39; . $table . &#39; (&#39; . implode(&#39;, &#39;, $fields) . &#39;) VALUES (&#39; . implode(&#39;, &#39;, $values) . &#39;)&#39;;
}
}
}
}
}
if ($sql)
{
return $this->query($sql, $querymode);
}
else
{
return false;
}
}
function setMaxCacheTime($second)
{
$this->max_cache_time = $second;
}
function getMaxCacheTime()
{
return $this->max_cache_time;
}
function getSqlCacheData($sql, $cached = &#39;&#39;)
{
$sql = trim($sql);
$result = array();
$result[&#39;filename&#39;] = $this->root_path . $this->cache_data_dir . &#39;sqlcache_&#39; . abs(crc32($this->dbhash . $sql)) . &#39;_&#39; . md5($this->dbhash . $sql) . &#39;.php&#39;;
$data = @file_get_contents($result[&#39;filename&#39;]);
if (isset($data{23}))
{
$filetime = substr($data, 13, 10);
$data = substr($data, 23);
if (($cached == &#39;FILEFIRST&#39; && time() > $filetime + $this->max_cache_time) || ($cached == &#39;MYSQLFIRST&#39; && $this->table_lastupdate($this->get_table_name($sql)) > $filetime))
{
$result[&#39;storecache&#39;] = true;
}
else
{
$result[&#39;data&#39;] = @unserialize($data);
if ($result[&#39;data&#39;] === false)
{
$result[&#39;storecache&#39;] = true;
}
else
{
$result[&#39;storecache&#39;] = false;
}
}
}
else
{
$result[&#39;storecache&#39;] = true;
}
return $result;
}
function setSqlCacheData($result, $data)
{
if ($result[&#39;storecache&#39;] === true && $result[&#39;filename&#39;])
{
@file_put_contents($result[&#39;filename&#39;], &#39;&#39; . time() . serialize($data));
clearstatcache();
}
}
/* 获取 SQL 语句中最后更新的表的时间,有多个表的情况下,返回最新的表的时间 */
function table_lastupdate($tables)
{
if ($this->link_id === NULL)
{
$this->connect($this->settings[&#39;dbhost&#39;], $this->settings[&#39;dbuser&#39;], $this->settings[&#39;dbpw&#39;], $this->settings[&#39;dbname&#39;], $this->settings[&#39;charset&#39;], $this->settings[&#39;pconnect&#39;]);
$this->settings = array();
}
$lastupdatetime = &#39;0000-00-00 00:00:00&#39;;
$tables = str_replace(&#39;`&#39;, &#39;&#39;, $tables);
$this->mysql_disable_cache_tables = str_replace(&#39;`&#39;, &#39;&#39;, $this->mysql_disable_cache_tables);
foreach ($tables AS $table)
{
if (in_array($table, $this->mysql_disable_cache_tables) == true)
{
$lastupdatetime = &#39;2037-12-31 23:59:59&#39;;
break;
}
if (strstr($table, &#39;.&#39;) != NULL)
{
$tmp = explode(&#39;.&#39;, $table);
$sql = &#39;SHOW TABLE STATUS FROM `&#39; . trim($tmp[0]) . "` LIKE &#39;" . trim($tmp[1]) . "&#39;";
}
else
{
$sql = "SHOW TABLE STATUS LIKE &#39;" . trim($table) . "&#39;";
}
$result = $this->link_id->query($sql);
$row = $result->fetch_assoc();
if ($row[&#39;Update_time&#39;] > $lastupdatetime)
{
$lastupdatetime = $row[&#39;Update_time&#39;];
}
}
$lastupdatetime = strtotime($lastupdatetime) - $this->timezone + $this->timeline;
return $lastupdatetime;
}
function get_table_name($query_item)
{
$query_item = trim($query_item);
$table_names = array();
/* 判断语句中是不是含有 JOIN */
if (stristr($query_item, &#39; JOIN &#39;) == &#39;&#39;)
{
/* 解析一般的 SELECT FROM 语句 */
if (preg_match(&#39;/^SELECT.*?FROM\s*((?:`?\w+`?\s*\.\s*)?`?\w+`?(?:(?:\s*AS)?\s*`?\w+`?)?(?:\s*,\s*(?:`?\w+`?\s*\.\s*)?`?\w+`?(?:(?:\s*AS)?\s*`?\w+`?)?)*)/is&#39;, $query_item, $table_names))
{
$table_names = preg_replace(&#39;/((?:`?\w+`?\s*\.\s*)?`?\w+`?)[^,]*/&#39;, &#39;\1&#39;, $table_names[1]);
return preg_split(&#39;/\s*,\s*/&#39;, $table_names);
}
}
else
{
/* 对含有 JOIN 的语句进行解析 */
if (preg_match(&#39;/^SELECT.*?FROM\s*((?:`?\w+`?\s*\.\s*)?`?\w+`?)(?:(?:\s*AS)?\s*`?\w+`?)?.*?JOIN.*$/is&#39;, $query_item, $table_names))
{
$other_table_names = array();
preg_match_all(&#39;/JOIN\s*((?:`?\w+`?\s*\.\s*)?`?\w+`?)\s*/i&#39;, $query_item, $other_table_names);
return array_merge(array($table_names[1]), $other_table_names[1]);
}
}
return $table_names;
}
/* 设置不允许进行缓存的表 */
function set_disable_cache_tables($tables)
{
if (!is_array($tables))
{
$tables = explode(&#39;,&#39;, $tables);
}
foreach ($tables AS $table)
{
$this->mysql_disable_cache_tables[] = $table;
}
array_unique($this->mysql_disable_cache_tables);
}
/**
+----------------------------------------------------------
* 启动事务
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
public function startTrans() {
//$this->initConnect(true);
if ( !$this->link_id ) return false;
//数据rollback 支持
if ($this->transTimes == 0) {
$this->link_id->autocommit(FALSE);
}
$this->transTimes++;
return ;
}
/**
+----------------------------------------------------------
* 用于非自动提交状态下面的查询提交
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function commit()
{
if ($this->transTimes > 0) {
$result = $this->link_id->commit();
$this->transTimes = 0;
if(!$result){
$this->error_message[][&#39;message&#39;] = &#39;MySQL Query Error&#39;;
$this->error_message[][&#39;sql&#39;] = $sql;
$this->error_message[][&#39;error&#39;] = $this->link_id->error;
$this->error_message[][&#39;errno&#39;] = $this->link_id->errno;
$this->ErrorMsg();
return false;
}
}
return true;
}
/**
+----------------------------------------------------------
* 事务回滚
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return boolen
+----------------------------------------------------------
*/
public function rollback()
{
if ($this->transTimes > 0) {
$result = $this->link_id->rollback();
$this->transTimes = 0;
if(!$result){
$this->error_message[][&#39;message&#39;] = &#39;MySQL Query Error&#39;;
$this->error_message[][&#39;sql&#39;] = $sql;
$this->error_message[][&#39;error&#39;] = $this->link_id->error;
$this->error_message[][&#39;errno&#39;] = $this->link_id->errno;
$this->ErrorMsg();
return false;
}
}
return true;
}
}
로그인 후 복사

代码当中加了几个方法,用于支持事务。

(2)更改cls_image.php的gd_version()方法,将这个方法改为静态方法,并且所有调用此方法的地方,都改为静态调用。

PHP5.6开始,已经不支持不兼容的上下文调用方法,并且产生 E_DEPRECATED 错误(以前是 E_STRICT)。

更改如下:

includes/cls_images.php,(gd_version方法体添加static关键字)
/**
* 获得服务器上的 GD 版本
*
* @access public
* @return int 可能的值为0,1,2
*/
static function gd_version()
{
....
}
로그인 후 복사

在好几处调用此方法的地方都改为静态调用,比如includes/cls_images.php的好几个方法在调用时使用类对象调用:

function make_thumb($img, $thumb_width = 0, $thumb_height = 0, $path = &#39;&#39;, $bgcolor=&#39;&#39;)
{
$gd = $this->gd_version(); //获取 GD 版本。0 表示没有 GD 库,1 表示 GD 1.x,2 表示 GD 2.x
。。。
}
로그인 후 복사

将其改为:

function make_thumb($img, $thumb_width = 0, $thumb_height = 0, $path = &#39;&#39;, $bgcolor=&#39;&#39;)
{
$gd = self::gd_version(); //获取 GD 版本。0 表示没有 GD 库,1 表示 GD 1.x,2 表示 GD 2.x
。。。
}
로그인 후 복사

还有includes/lib_base.php文件的gd_version函数,改为:

function gd_version()
{
include_once(ROOT_PATH . &#39;includes/cls_image.php&#39;);
return cls_image::gd_version();
}
로그인 후 복사

其他文件代码在调用时,最好改为调用lib_base文件的gd_version的函数。可以搜索更改。

(3)更改includes/lib_main.php文件的get_dyna_libs函数,该第一行的代码:

function get_dyna_libs($theme, $tmp)
{
$ext = end(explode(&#39;.&#39;, $tmp));
。。。
}
로그인 후 복사

更改为:

function get_dyna_libs($theme, $tmp)
{
$tmp_ext = explode(&#39;.&#39;, $tmp);
$ext = end($tmp_ext);
}
로그인 후 복사

end方法的接受的参数必须是引用传递值,这里使用了explode方法返回值,不可以直接套用。

(4)includes/cls_template.php代码:

preg_replace方法,自PHP5.5开始 /e修饰符已经废弃,所以要使用preg_replace_callback代替。此代替有多处:

fetch_str方法:

fetch_str($source)
{
。。。
return preg_replace_callback("/{([^\}\{\n]*)}/",&#39;self::select_replace&#39;, $source);
}
//新增的方法
private function select_replace($matches){
return $this->select($matches[1]);
}
로그인 후 복사

select方法:

function select($tag)
{
。。。
$pregReplace = preg_replace_callback("/(\&#39;\\$[^,]+)/" , function($matches){
return stripslashes(trim($matches[1],&#39;\&#39;&#39;));
}, var_export($t, true));
。。。
}
smarty_prefilter_preCompile方法:
$source = preg_replace_callback($pattern, function($matches){
return &#39;{include file=&#39;.strtolower($matches[1]). &#39;}&#39;;
}, $source);
로그인 후 복사

(5)将所有类的构造函数,都去除使用类名的构造函数,保留__construct():

涉及此改动的超多,用搜索一一找到并改动吧……这个就不列举了。

위 내용은 ecshop에서 PHP7을 수정하고 지원하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 채팅 명령 및 사용 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

ECshop의 아키텍처는 무엇입니까? ECshop의 아키텍처는 무엇입니까? Feb 23, 2023 am 09:32 AM

ecshop은 "B2C" 아키텍처입니다. ecshop은 기업과 개인이 개인화된 온라인 상점을 신속하게 구축하는 데 적합한 B2C 독립 온라인 상점 시스템입니다. 이 시스템은 PHP 언어 및 MYSQL 데이터베이스 아키텍처를 기반으로 개발된 크로스 플랫폼 오픈 소스 프로그램입니다.

ECshop 기사를 정렬하는 방법은 무엇입니까? ECshop 기사를 정렬하는 방법은 무엇입니까? Jun 16, 2023 am 11:30 AM

ECshop 기사 정렬 방법: 1. 게시 시간을 기준으로 정렬합니다. 기사 게시 시간을 수정하여 목록의 기사 순서를 제어할 수 있습니다. 2. 클릭수를 기준으로 정렬하려면 "기사 클릭 순위"를 설치하여 정렬할 수 있습니다. " 플러그인 기능, 이 플러그인은 기사 클릭 수를 계산할 수 있습니다. 3. 댓글 수를 기준으로 정렬합니다. "기사 댓글 순위" 플러그인을 설치하면 이 정렬 기능을 구현할 수 있습니다. 기사에 대한 댓글 수 4. 관련성순으로 정렬. 이 정렬 기능은 "검색 순위" 플러그인을 설치하여 구현할 수 있습니다.

엑스샵의 특징은 무엇인가요? 엑스샵의 특징은 무엇인가요? Feb 13, 2023 am 09:43 AM

특징: 1. 유연성, 사용자 정의 가능성 및 높은 확장성을 갖춘 오픈 소스 시스템 2. 독립적인 보조 개발 지원 3. 풍부한 템플릿 및 플러그인 4. 강력한 산업 적응성 5. 더 강력한 신뢰성 7. 모바일 H5 프레임워크 업그레이드, VUE 포괄적 교체를 기반으로 더욱 유연하고 개방적입니다. 8. 다단계 리베이트 기능, QR 코드, 포스터 및 기타 프로모션 방법 지원, 유통업체의 무제한 핵분열 개발; 관리 터미널이 완전히 새롭게 바뀌었고 UI가 단순하고 아름다워졌으며 운영 환경이 업그레이드되었습니다. 9. PHP7.2를 지원하고 성능이 두 배로 향상되었습니다.

ECshop 제품 관리 고급: 필드 추가 방법 알아보기 ECshop 제품 관리 고급: 필드 추가 방법 알아보기 Mar 12, 2024 pm 02:06 PM

Ecshop 제품 관리 고급: 필드를 추가하는 방법을 알아보세요. 특정 코드 예제가 필요합니다. 제품 관리를 위해 Ecshop을 사용할 때 특정 요구 사항을 충족하기 위해 일부 사용자 정의 필드를 추가해야 하는 상황이 자주 발생합니다. 필드를 추가하면 보다 정확한 제품 관리와 더 나은 사용자 경험을 얻을 수 있습니다. 이 글에서는 Ecshop에서 필드를 추가하는 방법을 소개하고 구체적인 코드 예시를 제공합니다. 먼저, 필드 추가의 필요성을 명확히 해야 합니다. 예를 들어 제품 세부정보 페이지에 '생산 날짜' 필드를 추가해야 합니다.

엑스샵은 어떤 프로그램인가요? 엑스샵은 어떤 프로그램인가요? Feb 16, 2023 am 10:38 AM

ECShop은 B2C 독립 온라인 상점 시스템으로, PHP 언어와 MYSQL 데이터베이스 아키텍처를 기반으로 개발된 크로스 플랫폼 오픈 소스 프로그램으로 기업과 개인이 개인화된 온라인 상점을 신속하게 구축하는 데 적합합니다. ecshop 몰 시스템의 특징은 다음과 같습니다. 1. 독립적인 2차 개발 지원 2. 풍부한 템플릿 및 플러그인 3. 강력한 산업 적응성 4. 소프트웨어 공급업체의 제약을 피합니다.

엑스샵 모델이 뭔가요? 엑스샵 모델이 뭔가요? Feb 22, 2023 am 09:37 AM

ECshop은 B2C 모델입니다. ECShop은 B2C 독립 온라인 상점 시스템으로 기업과 개인이 개인화된 온라인 상점을 신속하게 구축하는 데 적합합니다. B2C는 전자상거래 모델을 말하며 소비자에게 제품과 서비스를 직접 판매하는 소매 모델이기도 하다. B2C 전자상거래의 결제방식은 현금결제와 온라인 결제가 결합된 형태로 대부분의 기업이 물류를 선택한다. 운영 비용을 절감하기 위해 배송을 아웃소싱합니다.

ECshop에서 배송방법 취소하는 방법 ECshop에서 배송방법 취소하는 방법 Mar 03, 2023 am 09:56 AM

ECshop에서 배송 방법을 취소하는 방법: 1. "flow.dwt" 파일을 찾아서 연 후 "<!--{if $total.real_goods_count neq 0}-->...<!-- {를 삭제합니다. /if} - ->" 코드; 2. "js/shopping_flow.js"의 "checkOrderForm(frm)"을 "if (document.getElementById(...)"로 변경합니다.

EC숍 하단 저작권 제거 방법 EC숍 하단 저작권 제거 방법 Aug 08, 2023 pm 02:42 PM

ecshop 하단에 있는 저작권을 제거하는 방법: 1. 템플릿 파일을 수정합니다. 구체적인 위치는 다음과 같습니다: themes/your_theme 디렉토리, 이 디렉토리에서 footer.html 파일을 찾아 텍스트 편집기로 열고 다음이 포함된 코드 세그먼트를 찾습니다. 저작권 정보를 삭제하거나 댓글을 달아주세요. 2. 플러그인을 사용하려면 백엔드에 로그인하고 플러그인 관리를 클릭한 후 하단에서 저작권 및 기타 관련 키워드를 검색하고 적합한 플러그인을 선택하여 설치하세요. 3. 테마 구매는 ECShop 공식 홈페이지 등에서 구매하세요.

See all articles