ecshop php7 mysql_ecshop如何修改并支持PHP7

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

c38637c552a65e0b1b261ad358f85300.png

ecshop支持PHP7的修改方法

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

从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 = '

'$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't select MySQL database($dbname)!");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值