简体   繁体   中英

MySQL error: Call to undefined function mysql_connect() [file] on line 4

I keep getting this error, and i do not know much about PHP, but I would like to get started with it and with MySQL, but this error stops me from continueing with my learning!

Info
Server Program: Niginx
Installed Extras: PHP [5.6.4] | MySQL

Files:

<?php include "includes/config.php"; ?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" style+"text/css" href="css/main.css" />
<script type="text/javascript" language="javascript" src="javascript/main.js"></script>

</head>

<body>

</body>
</html>

config.php:

<?php

//connect to database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("chat") or die(mysql_error());

echo "Working";
?>

I assume you are following an old tutorial on connecting to MySQL databases.

The library for commands beginning with mysql_ is deprecated. This that you shouldn't be using when writing code in php, as it will be "turned off" in the future. Take a look at the mysql_connect() command's documentation for more information.

Thankfully, there's a number of alternative ways for you to connect to a database, which aren't going to be turned off any time soon! The one I'd recommend in your situation for simplicity is the mysqli_ library. Looks pretty similar, right? You use it in a fairly similar way too, check the documentation for mysqli_connect() .

Converting your mysql_ commands to mysqli_ is not hard, take a look at this answer for some more help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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