Here's my code to test connecting to the DB I just set up.
<?php
// DB connection info
$servername = "slateproject.database.windows.net";
$username = "";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
and the error
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.
Any clue what is preventing the connection?
Your database endpoint is database.windows.net, and it is the common endpoint of Azure SQL Service which is based on SQLServer but MySQL.
To connect to SQL Server in PHP, we need to enable php_sqlsrv extension, and the connection code sample:
<?php
$connectionInfo = array(
"UID" => "<user>#ttyir96emw",
"pwd" => "<your_passwd>",
"Database" => "garytestmb_db",
"LoginTimeout" => 30,
"Encrypt" => 1
);
$serverName = "tcp:ttyir96emw.database.windows.net,1433";
$conn = sqlsrv_connect($serverName, $connectionInfo);
?>
By the way, in Azure manage portal, the DASHBORAD page, we can click “Show connection string” to check the connection string and code examples in different language.
If you want to use MySQL as database, Azure provides ClearDB as MySQL server , you can follow How to Create a MySQL Database in Azure to create a MySQL database via ClearDB.
If you want to build your MySQL database in Azure VM, please refer Install MySQL on a virtual machine created with the classic deployment model running Windows Server 2012 R2.
Related
I am setting a new live server for my Laravel application its work perfectly on localhost but not on live server. Now its showing SQL State [2002] connection refused. I also try with mysqli_connect and PDO but the error remains the same. Is possible a problem with Hosting Provider?
<?php
$servername = "examrunner.com";
$database = "XXXXXXXX";
$username = "XXXXXXX";
$password = "XXXXXXXXXX";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Use server name as localhost. Because cPanel hosts your databases locally, use localhost as the database's hostname.
$servername = "localhost";
Please check below mentioned points to resolve this issue :
Check database and user exists
Make sure that Database user and Database connected to each other and you have given sufficient privileges to user.
If site hosted on current serve user hostname = 'localhost'
Try to print detailed error.
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.
Ok so I created an ubuntu instance from AWS and downloaded LAMP on it as you would in a regular Ubuntu OS. When I try to connect to the db from my php script it's rejecting the connection. saying "Connection failed: Connection refused". So I guess my question is this: Does amazon not allow you to connect to a db without using their RDS database service or am I putting something wrong here? (I've hidden some of the data for security purposes, the ... are numbers of my instance). When I put "ec2-34-...-..-64.compute-1.amazonaws.com" into the browser the apache message comes up so I don't see why this is not working as a server name?
$servername = "ec2-34-...-..-64.compute-1.amazonaws.com";
$username = "root";
$password = “hidden";
$dbname = "questions87";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
You need to change your EC2 Security Group Inbound Rules related with 3306, you can find that on the AWS FAQ. Then, you need to be sure that your user#YOURIP have all permissions on your MySQL database. For your Inbound Rules it is recommended to use a Custom Rule to your IP, not All Traffic.
Reference and further reading:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html
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!
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