Search code examples
phpmysqldreamweaver

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:

enter image description here

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!


Solution

  • 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