php5 升级 php7 版本遇到的问题处理方法总结

为了可以更好的提高系统的安全性,把原来的进销存系统源码升级,遇到了一些问题在这儿总结一下:php

1.mysql引擎在php7中不在支持会致使如下错误mysql

Uncaught Error: Call to a member function init() on null 。sql

其实在init()函数中,有extension_loaded("mysql"),即加载mysql扩展致使的,须要改成mysqli,不事后面的mysql操做函数都须要改为mysqli的对应类型数组

2.Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP;安全

Smarty has a deprecated constructor in /www/platform/library/Platform/View/Smarty/Smarty.class.php
[引自原文]:https://blog.csdn.net/sanbingyutuoniao123/article/details/78614077 php7

原来是smarty模板类仍是使用了php4的构造函数的写法,因此找到smarty类后,找到与类同名的函数,将函数名改函数

为__construct便可。fetch

PHP OOP使用和类名相同的方法名做为构造方法,是 PHP4 的写法,PHP 5中同时支持__construct和类同名方法,但__construct方法具备优先性。this

PHP 7开始使用和类名相同的方法名做为构造方法会报E_DEPRECATED级别的错误,提示在将来版本中会完全抛弃类同名方法做为编码

构造函数。但程序仍然会正常执行。

<?php
        class a{
                function a(){ // 此处改成 function __construct()
                        
                }
        }
?>

 3.Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP)

在php7中,MYSQL_ASSOC再也不是一个常量,将 MYSQL_ASSOC改成MYSQLI_ASSOC,意思是mysqli的方式提取数组,而再也不是mysql 。(缘由:mysql_fetch_arrayhan函数转为mysqli_fetch_array,参数没有修改

4.汉字显示为???(问号) 的解决办法

mysqli_query($conn,'set names utf8');在使用mysqli_query()查询数据的时候,最好指定字符的编码

相关文章
相关标签/搜索