Reputation: 255
I have the following PHP code:
(db/connect.php)
(index.php)
And I keep getting the following error:
I have a Linux CPanel and an external webhost: GoDaddy
Why can I not connect?
Thanks :)
Is this the db_user:
Upvotes: 0
Views: 91
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
Reputation: 2046
the directory should be as following
htdocs
|---test-db
| |---index.php
| |---db
| |---connect.php
|
Upvotes: 1
Reputation: 2500
Your connection link should be
require 'db/Connect.php';
That is Connect.php
starts with uppercase.
Upvotes: 0