How to connect to mysql online database?

Hello Friends there is some error which on display on my page when i was connect my online database from local wamp server or my pc.

Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://198.24.144.50:3306) in C:\wamp\www\ est\index.php on line 3

Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\ est\index.php on line 3
Could not connect: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Please solved these error and help me…

Thank you in advance.

Double check that all the connection data is correct and that the remote server allows remote connections.

Also please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn’t tie you down so much to a particular database server software.

Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.

I was checked every thing but i don’t got any type of mistake from my hand i can’t understand what is the problem in my code.

These is the code which i was use please check it is it correct or not.

<?php
$con = mysql_connect(“198.24.144.50”,“ewebtech_hima”,“hima!@#”);
if (!$con)
{
die('Could not connect: ');
}

mysql_select_db(“ewebtech_hima”, $con);

if (!($con))
{
die('Error: ');
}
echo “1 record added”;

mysql_close($con);
?>

Thank’s for your support…

As SpacePhoenix said, most of the time you are not going to be able to access a database remotely from a location outside of the server where the database resides.

Is 198.24.144.50 is a remote server? I hope “ewebtech_hima”,“xxxx” are not your real username and password? If so, you should probably delete em :expressionless:
So, if it’s a remote server hosted somewhere else, they rarely provide “out of the box” outside connections to a mySQL database. However, if I remember correctly, with cPanel I was once able to activate the “remote connection”. I think I had to allow it and add my IP somewhere.

If you could tell us where your database is hosted (what company, do you have cPanel, something else?) it could help.

<?php
// Create connection
$con=mysqli_connect(“example.com”,“peter”,“abc123”,“my_db”);

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>

Also, you could try to connect to your distant database with a mySQL client like SQLYog or mySQL bench for example.