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
Related
This question already has answers here:
mysql_connect(): No connection could be made because the target machine actively refused it
(12 answers)
Closed last month.
I was trying to make a simple database to write and read from and on pretty much one of the first steps I encountered a problem: it would not connect. I got the error message: "No connection could be made because the target machine actively refused it.". I looked at other stack overflow questions and they all had complex solutions involving changing the code of some things. I tried some, and nothing changed. I am using USBWebServer and phpMyAdmin. This is the index.php code that failed:
$servername = "127.0.0.1";
$username = "root";
$password = "usbw";
$databasetouse = "work times web database";
// Create connection
$mysqli = new mysqli($servername, $username, $password, $databasetouse);
// Check connection
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
echo "Connected successfully";
I tried changing $servername to "localhost" and nothing changed. When I first tried to log in to phpmyadmin it showed that my password was usbw and my username was root.
Maybe you should start your Apache and MySQL server through Xampp control panel and then try to connect.
I faced this error when I was learning laravel. Actually this happens when you database server is not being started.
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'
I'm creating a PHP application and have a local test enviroment on both my laptop and desktop.
EDIT: Generated logs in a pastebin.
I am using the WPN-XM Serverstack.
Everything worked fine beforehand, but now on my laptop, when I try to do anything that requires a connection with the database, it throws this error.
No connection could be made because the target machine actively refused it
Did some research and found out that it could be a problem with my firewall, turned it off, same result.
Read elsewhere that this is not an issue with my code, this makes sense since everything works on my desktop.
Things I've tried so far:
Restarted the webserver
Restarted the laptop
Turned off the firewall
Login to phpMyAdmin (Error: Cannot log in to the MySQL server)
Changed the port of the webserver to 8080
Any idea what might be causing this error?
For completeness, altough the problem is more than likely not in the code, here' s the connection file.
$name = "root";
$pass = "";
$db = "myDB";
$host = "localhost";
$connect = mysqli_connect($host, $name, $pass, $db);
if (mysqli_connect_errno()) {
echo "Could not connect to the mysql database. Error: " . mysqli_connect_error();
}
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 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