duanfu3390
2016-04-15 02:41 浏览 12
已采纳

如何修复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

Can anyone else tell me what is the problem in this system?

image

I'm currently using XAMPP V3.2.2

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答 默认 最新

  • 已采纳
    doumei1203 doumei1203 2016-04-15 02:52

    If you are using PHP 7 within your XAMPP then it wont work because that code is too old. mysql_select_db was removed in PHP 7.

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

    You will need to install PHP 5 to use that software.

    Edit: Pratik Solanki is correct also. 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)

    点赞 评论 复制链接分享
  • dpa89292 dpa89292 2016-04-15 03:05

    You forgot to include the database while connecting using mysqli_connect function. In your code, you declared a $mysql_database but you didn't use that.

    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 ");
    ?>
    
    点赞 评论 复制链接分享
  • dongqiang2358 dongqiang2358 2016-04-15 03:13

    You connected to database via mysqli module of php and you are trying to select your database via mysql module of php.

    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.

    Both are different and the only small mistake you made was making connection with mysqli and selecting db with mysql.

    Solution to this is making the whole connection along with selection of db via mysqli function

    点赞 评论 复制链接分享

相关推荐