Connection without answer, using PHP to Mysql remotely - php

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.

Related

Not able to make connection to mysql 8 in php

I am trying to connect to mysql server using php but it gives the following error
Connection failed: The server requested authentication method unknown to the client
mysql server version is 8.0.12 and php version is 7.2.9.
My code connect to mysql server
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "mypassword";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
This question has been previously asked before here but the solution did not work for me so I am asking this again.
Thanks
edit: I re-installed php now it gives the following for the same code
This page isn’t working
127.0.0.1 is currently unable to handle this request.
HTTP ERROR 500
I had a similar problem and found that you can change mysql authentication by running the following code via Workbench
ALTER USER root#localhost IDENTIFIED WITH mysql_native_password BY 'new-password-here'

Failing to access a Godaddy hosted MySQL server from AWS EC2

I have a MySQL server hosted in my Godaddy server. I want to access that database from my EC2 instance. However, I am unable to do so. I have added the public IP of my EC2 instance to the remote MySQL access hosts.
Things I have tried:
By using my Godaddy hosted website name as my server name.
Using my Godaddy hosted website IP address as my server name.
Every time I try to connect, It gives me the error:
Connection failed: Unknown MySQL server host '<hostname>:3306' (11)
Script I used:
<?php
$servername = "<hostname>:3306";
$username = "<username>";
$password = "<password>";
$dbname = "<dbname>";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
PS: I can successfully connect my MySQL workbench and a locally hosted server to my Godaddy database.
Try removing :3306 from $servername
Make sure the arguments are correct. mysqli() needs port as separate argument as described here
According to godaddy you need to enable Allow Direct Database Access for remotely connections.
Link here!

Remote MySQL connection using php not working

I can connect to the remote MySQL database from the MySQL Workbench using these credentials but when I try to connect using the php script I keep getting a connection timed out error. The MySQL server has its bind address already changed, it is running on a Linode server so I am not sure if that changes anything.
I'm using the php connect test script for MySQLi from W3 Schools.
<?php
$servername = "remote-db-IP";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
The exact error I get is
Warning: mysqli::mysqli(): (HY000/2002): Connection timed out in
/home/glavxfrw/public_html/db-connect-test2.php on line 7 Connection
failed: Connection timed out

Connect to remote MySql server with XAMPP

I have an script that i want it to run for more that 5 minutes. But my current hosting service does not allow me to modify the max_time_limit in the php.ini (That is set to 2 minutes)...
So i thought that i could run the script with XAMPP and send the data to my database but i cant connect to the remote database.
This is the code for the connection:
$servername = "217.70.186.108"; //I've also tried with the name of the webpage (metagame.gg)
$username = "the_username"; //the username is not root since I've read that root can only connect from localhost. This user has all privileges. This user was created with the permision to be connected from any server (%)
$password = "the_password";
$dbname = "the_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
It displays this error:
Connection failed: An error occurred during the attempt to connect because the connected party did not properly responded after a period of time, or failed in the established connection because connected host has failed to respond.
Any help would be highly appreciated

Connecting to mysql on another server.

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.

Categories