為了能夠更好的提升系統的安全性,把原來的進銷存系統源碼升級,遇到了一些問題在這兒總結一下:
1.mysql引擎在php7中不在支持會導致以下錯誤
Uncaught Error: Call to a member function init() on null 。
其實在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
原來是smarty模板類還是使用了php4的構造函數的寫法,所以找到smarty類后,找到與類同名的函數,將函數名改
為__construct即可。
PHP OOP使用和類名相同的方法名作為構造方法,是 PHP4 的寫法,PHP 5中同時支持__construct和類同名方法,但__construct方法具有優先性。
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()查詢數據的時候,最好指定字符的編碼