简体   繁体   English

如何修复PHP中的致命错误?

[英]How to fix fatal error in PHP?

I found a system that can generate a report I would like to study this system but when I try to generate the system the login was OK but when I put the password and username this error comes out: 我找到了一个可以生成报告的系统,我想研究该系统,但是当我尝试生成该系统时,登录正常,但是当我输入密码和用户名时出现此错误:

Fatal error: Call to undefined function mysql_select_db() in C:\\xampp\\htdocs\\inventory\\inventory\\db.php on line 8 致命错误:在第8行的C:\\ xampp \\ htdocs \\ inventory \\ inventory \\ db.php中调用未定义的函数mysql_select_db()

Can anyone else tell me what is the problem in this system? 谁能告诉我这个系统有什么问题吗?

image 图片

I'm currently using XAMPP V3.2.2 我目前正在使用XAMPP V3.2.2

If you are using PHP 7 within your XAMPP then it wont work because that code is too old. 如果您在XAMPP中使用PHP 7,则它将无法正常工作,因为该代码太旧了。 mysql_select_db was removed in PHP 7. 在PHP 7中删除了mysql_select_db。

http://php.net/manual/en/function.mysql-select-db.php http://php.net/manual/zh/function.mysql-select-db.php

You will need to install PHP 5 to use that software. 您将需要安装PHP 5才能使用该软件。

Edit: Pratik Solanki is correct also. 编辑: Pratik Solanki也正确。 The database is being connected using mysqli so depending on the other code in the system you can either change the database connect statement to mysql_connect and use PHP 5 (old mysql connector not recommended ) or change all the database statements to use mysqli instead in which case no PHP changes are needed ( recommended ) 数据库正在使用mysqli连接,因此,根据系统中的其他代码,您可以将数据库connect语句更改为mysql_connect并使用PHP 5( 不建议使用旧的mysql连接器),也可以将所有数据库语句更改为使用mysqli无需更改PHP( 推荐

You forgot to include the database while connecting using mysqli_connect function. 使用mysqli_connect函数进行连接时,您忘记了包含数据库。 In your code, you declared a $mysql_database but you didn't use that. 在您的代码中,您声明了$ mysql_database,但是您没有使用它。

Code: 码:

<php 
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "liveedit";

$bd = mysqli_connect ($mysql_hostname, $mysql_user, $mysql_password, $mysql_database) or die ("Opps something went wrong ");
?>

You connected to database via mysqli module of php and you are trying to select your database via mysql module of php. 你可以通过PHP的mysqli的模块连接到数据库,您要选择通过PHP MySQL的模块数据库。

Correct way to use it would be like this : 正确的使用方式如下:

mysqli_connect(dbhostname,dbusername,dbpassword,dbname)

mysqli can be used with the mysql native drivers and mysql can be used via the default libraries provided. mysqli可以与mysql本机驱动程序一起使用,并且mysql可以通过提供的默认库使用。

Both are different and the only small mistake you made was making connection with mysqli and selecting db with mysql. 两者都是不同的,您犯的唯一小错误是与mysqli建立连接并使用mysql选择数据库。

Solution to this is making the whole connection along with selection of db via mysqli function 解决方案是通过mysqli函数进行整个连接以及选择数据库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM