侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

ecshop适应在PHP7的修改方法解决报错的实现

php  /  管理员 发布于 7年前   378

ecshop这个系统,到目前也没见怎么推出新版本,如果是新项目,不太建议使用它。不过,因为我一直以来都在使用中,所以不得不更改让其适应PHP新版本。现在PHP 7已经出发行版了,所以更改来继续使用吧。具体的更改有以下方面:

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

从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 = '<' . "?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'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('gbk', 'big5', 'utf-8', 'utf8')))    {      $charset = str_replace('-', '', $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 = '')  {    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->settings = 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'] = 'MySQL Query Error';      $this->error_message[]['sql'] = $sql;      $this->error_message[]['error'] = $this->link_id->error;      $this->error_message[]['errno'] = $this->link_id->errno;      $this->ErrorMsg();      return false;    }    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;  }  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 = '', $sql = '')  {    if ($message)    {      echo "DTXB info: $message\n\n

"; //print('http://faq.comsenz.com/'); } else { echo "MySQL server error report:"; 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 函数 */ function selectLimit($sql, $num, $start = 0) { if ($start == 0) { $sql .= ' LIMIT ' . $num; } else { $sql .= ' LIMIT ' . $start . ', ' . $num; } return $this->query($sql); } function getOne($sql, $limited = false) { if ($limited == true) { $sql = trim($sql . ' LIMIT 1'); } $res = $this->query($sql); if ($res !== false) { $row = $res->fetch_row(); $res->free(); if ($row !== false) { return $row[0]; } else { return ''; } } else { return false; } } function getOneCached($sql, $cached = 'FILEFIRST') { $sql = trim($sql . ' LIMIT 1'); $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; } 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 = 'FILEFIRST') { $cachefirst = ($cached == 'FILEFIRST' || ($cached == 'MYSQLFIRST' && $this->platform != 'WINDOWS')) && $this->max_cache_time; if (!$cachefirst) { return $this->getAll($sql); } else { $result = $this->getSqlCacheData

以上就是小编为大家带来的ecshop适应在PHP7的修改方法解决报错的实现全部内容了,希望大家多多支持~

您可能感兴趣的文章:

  • centos7 + php7 lamp全套最新版本配置及mongodb和redis教程详解
  • CentOS 7.2.1511 编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11
  • thinkphp在php7环境下提示Cannot use ‘String’ as class name as it is reserved的解决方法
  • linux平台编译安装PHP7并安装Redis扩展与Swoole扩展实例教程
  • PHP7安装Redis扩展教程【Linux与Windows平台】
  • PHP7标量类型declare用法实例分析
  • PHP7新增运算符用法实例分析
  • PHP7匿名类用法分析
  • PHP7常量数组用法分析
  • PHP7.1方括号数组符号多值复制及指定键值赋值用法分析
  • PHP7.1新功能之Nullable Type用法分析
  • PHP7 新特性详细介绍
  • CentOS 7.2 下编译安装PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法详解(mini版本)
  • yum命令安装php7和相关扩展
  • golang 调用 php7详解及实例


  • 上一条:
    php获得文件夹下所有文件的递归算法的简单实例
    下一条:
    PHP之十六个魔术方法详细介绍
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客