How to fix Mysql error query PHP cPanel.

      

Usually, we get MySQL error query PHP mainly due to incorrect data in the PHP file or otherwise due to the permission or the ownership error.

Our technical team support will fix the Mysql error query PHP as a part of our server management plan. You can also take assistance from our technical team support 24/7 for fixing the error or any sort of installation.

Fixing the MySQL error query PHP

There might be many reasons to occur the error Message. 

Incorrect details in the PHP file 

By providing the wrong information may leads to the MySQL error. so you must provide the valid details in the PHP file.

One of our client reports has been displayed below.

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Perform a query, check for error
if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Glenn')"))
{
echo("Error description: " . mysqli_error($con));
}
mysqli_close($con);
?>

The error caused due to the wrong username provided under my _user section. you can fix the error by updating the username in the file.

Error due to incorrect permission.

In order to load a file properly in the server, you must provide the correct permission to the files. If any incorrect permission set for the file that leads to an error.

All the files were required to have the 644 permission. Run the following command to change the permission.

chmod 644 filename

Set the correct permission of the folder in which these files reside.Run the following command to change the folder permission

chmod 755 folder_name

Incorrect Ownerships

The ownership plays a prominent role, where its file can be either username or the root of the server. For all, you need to set the right one with the proper functionality of the file.

Run the commands to change the ownership of the file.

chown username:username filename

 Run the command to set ownership of a file as root.

chown root:root filename
Mysql server down

Ensure the Mysql server is running well. If the server is down then the PHP file wouldn’t work.

Run the command and check the Mysql status.

systemctl status mysql

.If suppose the MySQL server is down and gets an error you need to restart the MySQL server by running the following command.

systemctl restart mysql

.

Conclusion 

In brief, the MySQL error query PHP is mainly caused to incorrect database details in the PHP or it might be due to incorrect permission or incorrect ownership in the files. you can take assistance from our technical team support to fix the error under the server management plan.

Share:

More Posts

How to install FFmpeg on centos 8

                  The FFmpeg is a free and open-source solution that collect tools to handle multiple-media such as record, convert, stream audio and video. With the

Send Us A Message

Prevent your Website/Server from Downtimes

Get our experts to manage your server with weekly auditing and 24/7 monitoring