R. Jones
R. Jones

Reputation: 255

PHP not connecting with server

I have the following PHP code:

(db/connect.php)

enter image description here

(index.php)

enter image description here

And I keep getting the following error:

enter image description here

I have a Linux CPanel and an external webhost: GoDaddy

Why can I not connect?

Thanks :)

Is this the db_user:

enter image description here

Upvotes: 0

Views: 91

Answers (3)

Mike Stratton
Mike Stratton

Reputation: 475

Connect to Godaddy
Your mysqli connection lists "localhost" as the first parameter. You are trying to connect to a database locally. You need to connect to a host remotely, through Godaddy. You will need to lookup the connection information through your CPanel.
You will need to create and/or locate the following MySql database information:
1. hostname
2. username
3. db_password
4. db_name

Using Class mysqli
You are using: $db = new mysql. You need to use $db = new mysqli_connect
mysqli_connect needs four paramerters:

mysqli_connect("host_name","db_user","password","db_name");    

The code in your db/Connect.php should look like this:

<?php
$db = mysqli_connect("host_name","db_user","password","db_name");
// Check connection
if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
?>

http://www.w3schools.com/php/func_mysqli_connect.asp

Upvotes: 1

Chanaka Karunarathne
Chanaka Karunarathne

Reputation: 2046

the directory should be as following

htdocs
|---test-db
|    |---index.php
|    |---db
|         |---connect.php
|

Upvotes: 1

Al Amin Chayan
Al Amin Chayan

Reputation: 2500

Your connection link should be

require 'db/Connect.php';

That is Connect.php starts with uppercase.

Upvotes: 0

Related Questions