Reputation: 31
im trying to connect to my external sql database but I keep getting this error:
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\zconnect.php on line 10
Unable to connect to database! Please try again later.
This is the PHP script:
<?php
$hostname='111.11.111.11'; #this is not my real ip address
$username='root';
$password='password';
$dbname='database';
$usertable='users';
$yourfield = 'admin';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$query = 'SELECT * FROM ' . $usertable;
$result = mysql_query($query);
if($result) {
while($row = mysql_fetch_array($result)){
print $name = $row[$yourfield];
echo 'Name: ' . $name;
}
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
?>
Tried this but didn't work also:
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin4.1.14/"
# to give access to phpmyadmin from outside
# replace the lines
#
# Require local
#
# by
#
# Require all granted
#
Any help is appreciated!
Upvotes: 0
Views: 3087
Reputation: 672
First, I suggest SSH-ing your server and TCPing-ing or Netcat-ing (ok, I'm stopping) your remote MySQL server, so you see if it really can be accessed. Some hosts - mainly shared - require you to ask them to enable remote MySQL first (some have this option on CPanel).
Second, some MySQL servers whitelist some clients to access itself, exclusively. phpMyAdmin can help you in reading and setting this configuration.
Upvotes: 1