I try connect my remote server database in php but it's give bellow error
Host 'xx.xxx.xx.xx' is not allowed to connect to this MariaDB server in
My connection code like this
$servername = "my_server_address";
$username = "my_username";
$password = "my_password";
$dbname = "my_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
If your credentials are valid, you most likely need to configure MariaDB for remote client access.
See Configuring MariaDB for Remote Client Access
I had a similar issue after installing "xampp-windows-x64-7.3.6". After looking around and testing several solutions without any changes I did the following:
Uninstall xampp
Restart machine
Reinstall xampp
Restart machine
Importing old databases via phpmyadmin
All works fine for me now.
I did initially add a new user account. That might have caused the problem but I'm not testing this again.
You need to add new user in mariadb, goto privileges and add that can be accessed remotely
Related
When I try to run the below program I am get error as MySQL server has gone away.
<?php
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Google says that it is due to
2
Try to debug the problem. This can be caused by any number of things.
Commonly there are:
The MySQL server crashed
A comms problem between the client and server
Abusing the client library in a way not intended, perhaps sending commands out of order or sending junk through the socket.
I came to solution as to debug the problem. How to debug to find the correct reason as to why this error is happening?
First check version of php installed in your computer
The MySQLi extension is designed to work with MySQL version 4.1.13 or newer.
if you have required version
am suggesting you to unistall your server for example if is xampp then install it again
it will work
I recently set up RDS server using MySQL dataset and using EC2 beanstalk as a server.
I have been able to connect to dataset from
console of local machine using endpoint url, username, password
from PHP on local machine, using following code:
$servername = "xxxxx.xxxxxxxxxxxxxx.us-east-1.rds.amazonaws.com";
$username = "xxxxx";
$password = "xxxxxxx";
$dbname = "xxxxxxx";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname, 3306);
// Check connection
if (! $conn) {
echo "not connecting..!!";
die("Connection failed: " . mysqli_error($conn));
}
This works correctly, inserts data into the database in the RDS.
I ssh to EC2, check connect from console (using mysql -h -u -p). This too, work correctly. I can change the database from here and it is indeed reflected.
Next, I deploy the exact same code on EC2, and hope it works via PHP as well, as that code is already tested. But it does not.
I checked SELinux status is disabled
What else could be a problem?
I should mention: I am using Amazon Linux, I installed 'httpd' on local it.
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 created a working web app with login/register etc using a local dev server/wamp on my laptop, but require to move it all to linux server on a different system. I recreated the database identically in phpMyadmin and i am using the following connection string:
<?php
$server = '150.204.20.22';
$user = 'enramclo';
$pass = '***';
$dbname = 'enramclo';
$dbcon = mysqli_connect($server, $user, $pass, $dbname)or die("Can not connect to Server.");
?>
All these details are correct, but it simply will now not connect. I have little experienc eof linux so is there something I need to know as to why it will not work?
What is the os type? You might have SELinux enabled. Try to execute in shell and see if it's works
setenforce Permissive