The solutions I got are not working for me. Here is my code -
//Connect to database
$tempCon = new mysqli($domain, $username, $password, $database);
if ($tempCon->connect_errno) {
echo "Failed to connect to MySQL Database: (" . $tempCon->connect_errno . ") " . $tempCon->connect_error;
} else {
echo "connected";
}
The error I am getting is -
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2003): Can't connect to MySQL server on 'domain.info' (110) in /home/server/public_html/products/websites/EditWebsiteContent.php on line 8
Failed to connect to MySQL Database: (2003) Can't connect to MySQL server on 'doamin.info' (110)
Its because of the firewalls on the server which doesnot allow to connect.
If you are using shared hosting. You need to allow remote connecting to your database from your IP address.
Related
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.
try{
$mysqli = new mysqli('cpanelhost','cpanel_db_user','cpanel_db_password','cpanel_db','port');
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli ->connect_error;
exit();
}
$sql = "INSERT INTO table (column1, column2) VALUES ('value1', 'value2')";
$mysqli->query($sql) ;
$mysqli->close();
}
catch(Exception $e){
$mysqli->close();
return $e;
}
I would highly recommend you to:
Ask your hosting provider if they ALLOW remote MySQL connections.
Ask your host if port 3306 is open.
If the above is covered, then you will need to:
Add the IP address of the remote machine ( where you are trying to establish this connection ) to "Remote MySQL" in cPanel.
Use your server's hostname or IP as the MySQL Host in your connection configuration.
And if you still cannot establish a successful connection, I would recommend switching to a managed hosting provider which fully supports remote MySQL connections.
Hi so im trying to do a conection betwen my Apache server ( Xampp instalation ) with a remotely machine with a Mysql Server.
My php code :
<?php
$servername = '10.4.41.164:3306';
$username = 'admin';
$password = 'admin';
$db = 'AssistMe';
echo "Pepito";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
echo "Connected succesfully";
}
?>
The error that i get :
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
So before puting my question here i chequed that:
If i can do a ping to the server :
Ping to the server
I added a user in mysql that allows conections from anywhere : User in Mysql
I also allow the firewall of the server to connect from the 3306 port : Firewall of the server
And the last test was to Using Mysql WorkBench and testing if i can connect to my Mysql : Mysql WorkBench
So i dont know why i cant connect to my Mysql BDD remotly from my PHP code.
I am trying to establish a connection using mysqli as to connect with the database. Using the same credentials (host, username, and password), I have been able to successfully login in mysql workbench so I know the credentials are correct. However, I constantly receive the following error:
Failed to connect to MySQL:No such file or directory.
<?php
$con = mysqli_connect("...west-2.rds.amazonaws.com","usernameshown in aws rds","password","database name");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL:" . mysqli_connect_error();
}
?>
I'm using cPanel.
I created a database and a user with it's password.
But when im trying to connect to it using this code
$con=mysqli_connect("ahmadhammoud.com", "ahmadham_ahmad", "***********", "ahmadham_dbtest"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error();} mysqli_close($con);
I get
Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'ahmadham_ahmad'#'206.72.199.253' (using password: YES) in /home/xyz/public_html/scratches/sql/1/index.php on line 3 Failed to connect to MySQL: Access denied for user 'ahmadham_ahmad'#'some_ip_address' (using password: YES)Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /home/xyz/public_html/scratches/sql/1/index.php on line 10
Someone please help me.. is there something should be done in the settings of the cpanel or what :'\
Try:
$con=mysqli_connect("localhost", "ahmadham_ahmad", "***********", "ahmadham_dbtest"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error();} mysqli_close($con);
Use localhost if you are on same server as your mysql server. Then try change your username, ahmadham_ahmad to ahmadham:
$con=mysqli_connect("localhost", "ahmadham", "***********", "ahmadham_dbtest"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error();} mysqli_close($con);
I think you didnt enable remote connection. try to enable remote connection i think then it should work.
When I try to run working php code on my localhost instead of the web server, I am getting a connection error.
Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] Connection refused
Any idea how to get the MySQL username, db, and password to work from my local machine? I am using OS X Mountain Lion and Apache.
Do I have to login to the database server and add my IP?
Thanks!
Unless you've changed the default password root is allowed to connect to localhost, so that would be something like this :
<?php
$mysqli = new mysqli("localhost", "root", "", "");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
$mysqli = new mysqli("127.0.0.1", "user", "password", "database", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>
You can replace localhost by an ip, depends on how your database is configured to allow connections, using localhost or an explicit ip.
in case you have downloaded the code from a server and are trying to make a local replica then you need to update the connection parameters to match your local configuration. You need to update username, password , database etc. as per your local settings.. Hostname you may keep as localhost
Respond back if things are not working and add more detail on how things started like how you set up the code locally..and what things you have tried yet..