我收到以下错误:
代码中的错误是什么?
[27-May-2018 20:37:37 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; FGMembersite has a deprecated constructor in /home/gurudev/public_html/user/include/fg_membersite.php on line 24
[27-May-2018 20:37:37 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; FormValidator has a deprecated constructor in /home/gurudev/public_html/user/include/formvalidator.php on line 66
[27-May-2018 20:37:58 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; FGMembersite has a deprecated constructor in /home/gurudev/public_html/user/include/fg_membersite.php on line 24
[27-May-2018 20:37:58 UTC] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; FormValidator has a deprecated constructor in /home/gurudev/public_html/user/include/formvalidator.php on line 66
[27-May-2018 20:37:58 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/gurudev/public_html/user/include/fg_membersite.php:773
Stack trace:
#0 /home/gurudev/public_html/user/include/fg_membersite.php(729): FGMembersite->DBLogin()
#1 /home/gurudev/public_html/user/include/fg_membersite.php(86): FGMembersite->SaveToDatabase(Array)
#2 /home/gurudev/public_html/user/register.php(6): FGMembersite->RegisterUser()
#3 {main}
thrown in /home/gurudev/public_html/user/include/fg_membersite.php on line 773
答案 0 :(得分:1)
[27-May-2018 20:37:37 UTC] PHP已弃用:具有相同名称的方法 因为他们的类不会是未来PHP版本的构造函数; FGMembersite有一个弃用的构造函数 第24行/home/gurudev/public_html/user/include/fg_membersite.php
这意味着该类的构造函数以php将来不再支持的方式命名。
class FGMembersite{
public function FGMemmbersite() : void{
echo "something";
}
}
class FGMembersite{
public function __construct() : void{
echo "something";
}
}
new FGMembersite();
这两个类都会回应"某些东西",区别在于第一个中的构造函数方法将来不再适用于未来的php版本,因为它们与类本身的名称相同;它必须是__construct()
它警告您,您的代码可能会破坏该行。
答案 1 :(得分:0)
请检查您正在使用的PHP版本。 mysql_connect()
是PHP 5的一部分。
从官方网站引用:
警告强> 此扩展在PHP 5.5.0中已弃用,并且已在PHP 7.0.0中删除。相反,应使用
MySQLi
或PDO_MySQL
扩展名。
如果您仍想使用mysql_connect()
,请使用包含PHP 5.x的相应服务器安装,例如,XAMPP 5.6.36
您可以轻松地将所有PHP 5.x代码转换为PHP 7.x.我亲自将这个tool用于我的一些项目,它就像一个魅力。但是在某处备份原始代码。