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.
Related
I have a web server running on a raspberry pi model B, i have port forwarded port 80 for http and this is successfully working. However, because there is a login page on my site, i need mysql. How do i connect my current site using php to a mysql date base, will i need to port forward the mysql port?
i've pasted the code below:
<?php
/*PHP for connecting website to database*/
$servername = "ip/hostname";
$database = "database";
$username = "username";
$password = "password";
$conn = mysqli_connect($servername, $username, $password,
$database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
No, you will not need port forward. It's not the user who is logging in into mysql database, it's the php server doing the connection.
As a server hostname in your php file you can simply use localhost, if the mySQL db and php server are on same device/machine.
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 have a website that has a page that needs to show all the information that is in the local MySQL server (not in the hosting). How am I gonna do that?
I only tried to change the connection details but no luck on that matter.
db_connect.php (connect to hosting server)
<?php
$servername = "localhost";
$username = "xxx";
$password = "yyy";
$database = "dbdb";
$conn = new mysqli($servername, $username, $password, $database);
if($conn->connect_error){
die("FAILED TO CONNECT : " . $conn->connect_error);
}
?>
to db_local.php (connect to my local server)
<?php
$servername = "192.168.x.xx";
$username = "";
$password = "";
$database = "info";
$conn = new mysqli($servername, $username, $password, $database);
if($conn->connect_error){
die("FAILED TO CONNECT : " . $conn->connect_error);
}
?>
Is it possible? I only need to do that as a first aid solution in my main problem. I am getting this kind of error:
FAILED TO CONNECT : Can't connect to MySQL server on '192.168.x.xx' (110)
mysql might only accept connections from localhost, if you are connecting to the db from your local computer then you need to change the address to localhost
If you are not connecting to the DB via local machine then you need to make sure that port 3306 is open on the server, selinux is off ( assuming you are on linux ) and that you have the proper credentials.
If that doesnt work edit your my.cnf and change the line bind-address: 127.0.0.1 to the machines local ip.
Hope this works...
https://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
connecting to mysql server on another PC in LAN
My system using core php and it is working fine in localhost. When I host into live then there is an error occurs site not working. I hosted in GoDaddy server and below are the code.
//connection code
<?php
$servername = "localhost";
$username = "*****";
$password = "*****";
$dbname = "******";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
But i get below error in browser
PHP Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
in G:\PleskVhosts\projectname.com\httpdocs\pages\header.php on line 13
Please help me to fix it.
Not a problem in your code. May be service is not listing on your port or firewall is blocking your connection. In this case most possible reason is firewall.
You need to try "netstat -anb" for checking a running expected port. Here is a link my be help you:
No connection could be made because the target machine actively refused it?
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