简体   繁体   中英

How to fix error in dbconn file when upload php mysql project to free webhosting site?

I've been trying to upload my PHP MySQL(in Dreamweaver) project to a free web-hosting site.

When I logged in, there is an error that appear in dbconn.php file.

The error is shown below:

在此处输入图片说明

and here's the code in my dbconn.php file:

<?php
/* php& mysqldb connection file */
$user = 1350048; //mysqlusername to db
$pass = "password"; //mysqlpassword to db
$host = "eskl.freeoda.com"; //server name or ipaddress
$dbname= 1350048; // db name in server freeoda
$dbconn= mysql_connect($host, $user, $pass);
if(isset($dbconn)){
mysql_select_db($dbname, $dbconn) or die("<center>Error: " . mysql_error() . "</center>");
}
else{
echo "<center>Error: Could not connect to the database.</center>";
  }
?>

I would really appreciate if anyone can teach me how to solve this.. thanks in advance!

As Kerbholz already stated, don't use mysql_* functions, they are really outdated.

Instead use mysqli:

$servername = "eskl.freeoda.com";
$username = "1350048";
$password = "password";
$database = "1350048";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

For your error it got mostly something to do your host doesn't allow remote connections. Try to change the serverhost to localhost or 127.0.0.1

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