0

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

2
  • What is the root of index.php..? is it in db directory of outside the db directory? Commented Oct 11, 2015 at 10:56
  • Your title is incorrect. you are using db/Connect.php) with a capital "C" but the screenshot shows your php file with lowercase "c" (connect.php). Commented Oct 11, 2015 at 11:27

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the quick response - I have edited the question above - is this what the user should be: User: cpses_rhoeIBPMZK@localhost
No, you only need to enter the user name. Here is a link to Go Daddy that might help. godaddy.com/help/connecting-to-mysql-using-php-216
1

the directory should be as following

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

2 Comments

Thanks for the quick response - this is the directory that i am using - and for some reason it is still not working
you should check the file name.. it is connect.php, not Connect.php.. It is a good programming practice that not using capital letters for first letter of the file.. use camelCase..
0

Your connection link should be

require 'db/Connect.php';

That is Connect.php starts with uppercase.

2 Comments

Thanks for the quick response, I was just wondering why the capitalisation matters in this instance?
*nix (Linux, Unix & MacOS) all use filesystems that are case sensitive which means that Connect.php and connect.php are two different files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.