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

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 "<b>DTXB info</b>: $message\n\n<br /><br />";
      //print('<a href="http://faq.comsenz.com/?type=mysql&dberrno=2003&dberror=Can%27t%20connect%20to%20MySQL%20server%20on" target="_blank">http://faq.comsenz.com/</a>');
    }
    else
    {
      echo "<b>MySQL server error report:";
      print_r($this->error_message);
      //echo "<br /><br /><a href='http://faq.comsenz.com/?type=mysql&dberrno=" . $this->error_message[3]['errno'] . "&dberror=" . urlencode($this->error_message[2]['error']) . "' target='_blank'>http://faq.comsenz.com/</a>";
    }

    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的修改方法解决报错的实现全部内容了,希望大家多多支持~

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索ecshop适应在php7
ecshop自适应模板、ecshop 自适应、ecshop 分辨率 自适应、ecshop横幅自适应、ecshop ajax.call实例,以便于您获取更多的相关知识。

时间: 2024-11-08 21:16:48

ecshop适应在PHP7的修改方法解决报错的实现_php实例的相关文章

ofbiz crud-小白求教,ofbiz做crud,修改和删除报错

问题描述 小白求教,ofbiz做crud,修改和删除报错 错误如上,如何解决,望高人指教 解决方案 http://www.myexception.cn/open-source/1504679.html 解决方案二: 参考这个博客:http://www.tuicool.com/articles/J3MNRf7

报空指针异常,但是我debug到对象是有值的,执行查询方法就报错,错误信息如下:

问题描述 报空指针异常,但是我debug到对象是有值的,执行查询方法就报错,错误信息如下: 5C java.lang.NullPointerException at net.shop.services.manage.account.impl.AccountServiceImpl.selectCount(AccountServiceImpl.java:44) at net.shop.web.action.manage.account.AccountAction.unique(AccountActi

jdbc-ResultSet循环遍历时,对数据进行修改,但是报错ResultSet is read only

问题描述 ResultSet循环遍历时,对数据进行修改,但是报错ResultSet is read only Statement ps_page = l_conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE ResultSet.CONCUR_UPDATABLE ); ResultSet rs_page = ps_page.executeQuery(qii.l_sql_page); while(rs_page.next()){ String

jdbc连接-我用JDBC连接数据库的时候,添加修改数据时候报错。

问题描述 我用JDBC连接数据库的时候,添加修改数据时候报错. 解决方案 你看第一行提示的信息是不支持Object类型:你可以定义一个字符串数组然后将需要的参数放到这个数组里的:而且你下面的pre.setObject(i+1o[i]);//假如你的数据是一个整型的那Object就不是它了你可以说它是Object的但是Object不是它: 如果回答对您有帮助请采纳 解决方案二: 很明显 jdbc不支持执行object数据操作 解决方案三: 错误为不支持java类型 object,应该是你的类型 p

ad-Java ldap修改AD属性报错

问题描述 Java ldap修改AD属性报错 用Java ldap做一个域用户某一个属性信息修改功能 LdapContext ctx = xxx; 已经用域管理用户连接上了,没问题. ModificationItem modificationItem[] =new ModificationItem[1]; modificationItem[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,new BasicAttribute("empl

java web-java.lang.NoSuchMethodException有query方法还报错是怎么回事?

问题描述 java.lang.NoSuchMethodException有query方法还报错是怎么回事? java.lang.NoSuchMethodException: cn.cultivator.action.CategoryAction.query() java.lang.Class.getMethod(Class.java:1605) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.ge

exception-用java写了一个获取页面内容的方法,报错返回521码

问题描述 用java写了一个获取页面内容的方法,报错返回521码 我的代码如下: strUrl = "http://www.tlnews.cn/dzb/tlrb/html/2016-04/15/node_164.html"; public static String getUrlStr(String strUrl, String charSet){ String urlStr = ""; try { URL url = new URL(strUrl); URLCon

java中如果一个类不是某个父类的子类,然后去调用父类的方法会报错吗

问题描述 java中如果一个类不是某个父类的子类,然后去调用父类的方法会报错吗 java中如果一个类不是某个父类的子类,然后去重写父类的方法会报错吗 比如 public Cxff { super.onCreate( )}有语法错误吗 解决方案 肯定会报错,举个不太恰当的例子,我爸的钱我可以随便花,陌生人要是想花就花,那不是要上天了? 解决方案二: 会报错的,它不是某个父类的子类,它的super就不会指向你说的那个父类 解决方案三: 肯定报错啊 没有继承父类,也没有实现接口的话 没有方法重写这一说

Centos6修改sysctl.conf报错解决方法

这几天一直在折腾VPS优化,openvz构架的,在做linux内核优化的时候,执行/sbin/sysctl -p老报错: error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key error: "net.bridge.bridge-nf-call-iptables" is an unknown key error: "net.bridge.bridge-nf-call-arptables&