I'm hosting a php server on localhost using command line on Windows, and I'm trying to establish a connection between it and a Mysql database hosted on my school's servers.
I try to make the connection like so:
$db = mysqli_connect('host', 'username', 'password', 'db_name');
which results in this error:
Warning: mysqli_connect(): (HY000/2002): 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.
What might be the cause of this error?
Related
I can't connect to MySQL RDS instance on AWS through php. It gave me this error:
Warning: mysqli::__construct(): (HY000/2002): 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:\xampp\htdocs\RESULTS\conne\New Text Document.php on line 7
Connection failed: 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.
Could you please help me to get through. I am new to AWS and stuff. So I would be much thankful if you could describe this issue in detail.
Is it possible that you do not have the ip address of the server hosting your php application whitelisted under your rds security group? Something like this: https://stackoverflow.com/a/21498471/6763406
I'm trying to connect to a remote MySql database and I get this error message:
Warning: mysqli_connect(): (HY000/2002): 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:\myLocalDiectory\RemoteConn.php on line 9 "Resource not found" error 404.
Here's my php file that I'm trying to use:
<?php
define("DB_SERVER", "serverName");
define("DB_USER", "userName");
define("DB_PASS", "password");
define("DB_NAME", "dbName");
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
Am I missing something? Thanks for any help!
The first thing that I would check (if you haven't done so) is that you can in fact connect to the database from the computer that runs your PHP script. This to rule out a network or firewall problem.
The first thing would be pinging the server. In a DOS prompt run:
ping servername
Where "servername" is the same string that you put in your PHP script above. If this does not reply with a string similar to the one below, specifically, the first word is not "Reply":
Reply from 192.168.239.132: bytes=32 time=101ms TTL=124
This means that there is most likely no connectivity between the computer running the PHP script an the mysql server. I would then check if the server and the computer are properly connected to the network, if the server is up, an if there is not firewall in your computer running the PHP script or on the server.
Now, if your test above shows "Reply" to the ping, you can test if you can connect to the Mysql service from your php server. For this you can use Mysql workbench (http://dev.mysql.com/downloads/workbench/) and from there create a connection with the database parameters that you are giving to your script. If you cannot connect with Mysql workbench, you might need to disable a firewall in your Mysql server, a firewall in your computer running PHP, or enable the Mysql server to accept remote connections for the database and username that you use in your PHP script (some distributions Mysql server are installed to only accept local connections for safety).
If the problem is a permission in the server (the user can only connect locally but not from a remote computer for instance), you can enable the permission in the Mysql server with the GRANT command: http://dev.mysql.com/doc/refman/5.1/en/grant.html
define("DB_USER", "userName");
Try root instead of userName and define DB_HOST.
I am doing Remote database connection in php, and getting this error:
Warning: mysql_connect(): Host 'AT-PC-6' is not allowed to connect this MySql server in
C:\xampp\htdocs\programs\remote.php on Line ($con=mysql_connect('192.168.1.57','root','') or die ("Conection Failed");)
I am trying to connect to the database that is hosted on my server through my local machine.
my server has cPanel 11, and it is a typical shared server, powered by CentOS, PHP and MySQL installed.
to be precise i am holding the reseller account in the same server. i want to access the database between different accounts or domains.
in MySQL connection String i tried defining the domain name, and it isn't working. here is what i tried.
<?php
$link = mysql_connect('mydomain.com', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
this is giving the following error
Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://bhatkalnews.com:3306) in C:\wamp\www\test\conn.php on line 4
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\test\conn.php on line 4
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\test\conn.php on line 4
what do i have to define in connection string to make it work?
Firewall ?
try
telnet mydomain.com 3306
on the command line.
If that doesn't work, the connection is blocked by a firewall, most likely
Did you try adding the port explicitly:
mysql_connect('mydomain.com:3306', 'mysql_user', 'mysql_password');
or the port youre running on if not the default 3306. This of course assumes your server allows remote connections.
Also make sure the user in quest has access from the IP address youre connecting from. This isnt youre issue right now, but it may be the next question you have after you get the server to respond :-)
Please refer,
http://forums.mysql.com/read.php?52,294772
You need to add your IP address/range on Access Host list in Remote MySQL in cPanel.
I am using Zend_Rest_Client to connect Zend_Rest_Server, everything seems to be alright, but when I try to get() from the server I recieve this error:
Zend_Http_Client_Adapter_Exception:
Unable to Connect to
tcp://localhost:80. Error #10060: 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:\www\zf_1_72\library\Zend\Http\Client\Adapter\Socket.php
on line 148
here is code, which I use
$client = new Zend_Rest_Client('http://localhost/my_application/api/index/');
$client->auth($key);
$result = $client->get();
thank's for any advice
This thread suggetss the issue may be with the 'localhost' name - try using 127.0.0.1 instead.