Error trying to connect to Database

My website works fine on my computer using Apache which includes MySQL.
But, I upload my files on 000webhost and it doesn’t work. I get the following error message at the first attempt to access my database.

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /storage/h4/546/1058546/public_html/HA_LogInCheck.php:95 Stack trace: #0 {main} thrown in /storage/h4/546/1058546/public_html/HA_LogInCheck.php on line 95

I’m not sure where the error is because the line reference provided does not seem exact but it is in one of the following:

$link = mysql_connect('localhost', $username, $password);
if (!$link){die('Not connected : ' . mysql_error());}
$db_selected = mysql_select_db($database, $link);
if (!$db_selected){die ('Can\'t use ' .$database .':'. mysql_error());}
$query = "SELECT * FROM users WHERE userid = '$UserID'";

So what version of PHP do you run locally?

I’m using Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.19

Hit up 000webhost.com > general settings and use PHP 5.6 then? :slight_smile:

OK, I changed it to 5.6 but I still get an error but different error (below).
Many many thanks for your help - my sanity is slowly coming back thanks to you.
Now it’s 1:10 am here so I’m off to bed and look forward to see more from you in the morning.
Hope you don’t mind. I’ve had a hard day.

Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /storage/h4/546/1058546/public_html/HA_LogInCheck.php on line 95

Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /storage/h4/546/1058546/public_html/HA_LogInCheck.php on line 95
Not connected : php_network_getaddresses: getaddrinfo failed: Name or service not known

host is localhost yes?

I had ‘localhost 3306’ (left over from a test.
I have changed it to ‘localhost’ and I have tried it with all combinations of ‘root’ and ‘vipko’ as user and with and without my database password and in each case I get the following error:

Warning: mysql_connect(): ProxySQL Error: Access denied for user ‘vipko’@‘2a02:4780:bad:f00d::2’ (using password: YES) in /storage/h4/546/1058546/public_html/HA_LogInCheck.php on line 95
Not connected : ProxySQL Error: Access denied for user ‘vipko’@‘2a02:4780:bad:f00d::2’ (using password: YES)

user will be whatever you generate within 000webhost.com > manage database

username and database will always start ID123456_username ID123456_database

for example

I understand what you’re saying and I have now used these names but I still get the error:

Warning: mysql_connect(): ProxySQL Error: Access denied for user ‘id1058546_mglp’@‘2a02:4780:bad:f00d::2’ (using password: YES) in /storage/h4/546/1058546/public_html/HA_LogInCheck.php on line 95
Not connected : ProxySQL Error: Access denied for user ‘id1058546_mglp’@‘2a02:4780:bad:f00d::2’ (using password: YES)

My code is:
$username = “id1058546_mglp”;
$database = “id1058546_homeaccounting”;

$link = MySQL_connect(‘localhost’, $username, $password);
if (!$link){die(‘Not connected : ’ . mysql_error());} (***** I think execution stops here *)
$db_selected = mysql_select_db($database, $link); (
Doesn’t even get to use $database ****)
if (!$db_selected){die (‘Can’t use ’ .$database .’:’. mysql_error());}
$query = “SELECT * FROM users WHERE userid = ‘$UserID’”;

Also I checked MySQL documentation on “MySQL_connect” and it says it is deprecated and to use “MySQL_real_connect” instead. I tried that but I get the following which indicates “MySQL_real_connect” is not a valid function even if the documentation says it is. Perhaps it’s a question of MySQL versions.

Fatal error: Call to undefined function mysql_real_connect() in /storage/h4/546/1058546/public_html/HA_LogInCheck.php on line 95

@mglp you need to use “mysqli”, as “mysql” is deprecated function.

If you want to use “mysql” then you need to downgrade your php version to “5.4” from “settings – general --php version”.

Thank you @akhilkumar332 for your help.
However, I’ve tried “mysqli” and I’ve tried PHP V5.4 and in each case, I get the same problem and essentially the same error messages.

what is your domain name??
Are you still facing the same??

Domain = vipko-int.comeze.com
I still have the problem if that’s what you’re asking.

@akhilkumar332

I finally found the problem. It was due to an incorrect DB password. I checked this many times and I had understood that my DB password was the same as my website password. When I changed my DB password and then used this in MySQL_connect, it worked beautifully.

1000 thanks for your help.

1 Like

Post back if you have any issues. :slight_smile: