I am getting following error while connecting to my database - php

I am getting following error while connecting to my database:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at admin#main-hosting.eu to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
php_error.log file:
[25-Feb-2017 09:45:09 UTC] PHP Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'mysql.hostinger.in' (4 "Interrupted system call") in /home/u191892126/public_html/API/connect.php on line 8
My php file:
<?php
$servername = "mysql.hostinger.in";//var deceleration I tried "localhost" too
$username = "u1918921**_root";
$password = "*********";
$dbname = "u191892126_acare";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>

It was a server's error tried it again(it took 4 hours) and everything was working fine.

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'

PHP remote connection on live is not working [duplicate]

This question already has answers here:
PHP Warning: mysqli_connect(): (HY000/2002): Connection refused
(8 answers)
Closed 4 years ago.
I am trying to access remote MySQL server by its IP using PHP.
Here is my code:
$servername = "100.XXX.XXX.XXX:3306"; // MySQL IP
$username = "root";
$password = "Password012";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "success";
}
This is working fine on my local machine but not on live.
I am getting this error:
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in [...]
Any suggestions?
You need to allow remote connection on your mysql server.
To do that, execute the following command in your mysql server. Please change the databasename and username from the following command, before execute the command
GRANT ALL PRIVILEGES ON databasename . * TO 'username'#'%';

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

mysqli_connect connection error in GoDaddy

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?

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

Categories