Show query error mysql

show query error mysql › doc › refman › show-errors. The MySQL details in the PHP file must be set correctly. If any data is incorrect then an error will display. Recently, one of our customers. mysqli_connect_error(); } // Perform a query, check for error if (!mysqli_query($con,"INSERT INTO employees (First_Name) VALUES ('David')")) {.

Show query error mysql - think, that

Display Errors Using MySQLi Error Functions

  1. PHP Error Functions
  2. Conclusion

is a PHP function used to access the MySQL database server. You can use this extension if you have MySQL version 4.1.13 or above.

There are various functions that you can use to perform different functions in PHP. In this article, we will learn error functions.

We will also see how and where to use code examples and observe the outputs. For this tutorial, we will use MySQL version 8.0.27 and PHP version 7.4.1.

PHP Error Functions

In this tutorial, we will learn about the following PHP error functions:

    All these functions can be used in object-oriented style and procedural style. Let’s understand both syntax using the function.

    Syntax of Function in Object Oriented Style

    Syntax of Function in Procedural Style

    Function in MySQL

    This function is used to output the last error description for the most recent function call (if there is any). It is used when you want to know whether the query has an error or not.

    returns the error description and empty string if there is no error. See the following example.

    Example Code Using Procedural Style:

    The code given above tries to make the connection using , , , variables and save this connection into the variable.

    function will take this connection variable as a parameter and check if there is any error caused by the recent function call which is here.


    display errors using mysqli error functions - no error using mysqli_error

    Now, change the table name in the query from to and observe the output given below.


    display errors using mysqli error functions - error using mysqli_error

    We, as a developer, can easily understand that there is no table in the database (this is what it means in the above error).

    Keep the table name changed and replace the line with to practice and understand the object oriented style using error function.

    Function in MySQL

    works the same as does, but it will return the error code instead of the error description.

    Write the following code to practice and understand. You may have noticed that we use a procedural style to practice this function.

    The code given above will show the following output where you will see a number as an error code.


    display errors using msyqli error functions - error using mysqli_errno

    The question is, why do we use this function to show the numbers only? Because if you want to print a user-friendly error message (custom message), you can use this error code in statements.

    See the following code and its output below.


    display errors using mysqli error functions - custom error message using mysqli_errno.png

    Function in MySQL

    This function is very useful for knowing the error code, SQL state, and error description because this function returns an array containing all the necessary information.

    Example Code:


    display errors using mysqli error functions - error list using mysqli_error_list

    Function in MySQL

    returns the error description from the last connection if there is any. Although, the function also tell about the unsuccessful connection but returns the error that we can understand easily.

    Write the following code first, see its output, and then we’ll compare it with the output produced by .


    display errors using mysqli error functions - error using mysqli_connect_error part a

    See the output given above; you can see that the error we can understand is somewhere in the middle.

    Imagine, if you have 2 or 3 errors, it would not be easy to find out. Now, use the and see the difference using the following code and output.


    display errors using mysqli error functions - error using mysqli_connect_error part b

    The above output clearly says that there is no user named , which does not allow you to access the database.

    Function in MySQL

    This function behaves like but displays the error code rather than the error message. We can use this error code to write custom error messages.

    Example Code:


    display errors using mysqli error functions - error using mysqli_connect_errno


    Considering all the discussion and examples, we have concluded two main categories. The first category shows the errors about SQL queries and the other about database connections.

    Depending on the project needs, we can print the error message or the error code in each category.

    Write for us

    DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

    Related Article - MySQL Error

  • Fix Data Is Truncated for a Column Error in MySQL
  • Common Errors When Using MySQL

    This section lists some errors that users frequently get. You will find descriptions of the errors and how to solve the problems here.

    MySQL server has gone away Error

    This section also covers the related Lost connection to server during query error.

    The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection. By default, the server closes the connection after 8 hours if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld.

    Another common reason to receive the MySQL server has gone away error is because you have issued a “close” on your MySQL connection and then tried to run a query on the closed connection.

    If you have a script, you just have to issue the query again for the client to do an automatic reconnection.

    You normally can get the following error codes in this case (which one you get is OS-dependent):

    Error code



    The client couldn’t send a question to the server.


    The client didn’t get an error when writing to the server, but it didn’t get a full answer (or any answer) to the question.

    You will also get this error if someone has kills the running thread with kill #threadid#.

    You can check that MySQL hasn’t died by executing mysqladmin version and examining the uptime. If the problem is that mysqld crashed you should concentrate one finding the reason for the crash. You should in this case start by checking if issuing the query again will kill MySQL again. See Section A.4.1.

    You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld gets a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by starting mysqld with the -O max_allowed_packet=# option (default 1M). The extra memory is allocated on demand, so mysqld will use more memory only when you issue a big query or when mysqld must return a big result row!

    If you want to make a bug report regarding this problem, be sure that you include the following information:

    • Include information if MySQL died or not. (You can find this in the hostname.err file. See Section A.4.1.

    • If a specific query kills mysqld and the involved tables where checked with CHECK TABLE before you did the query, can you do a test case for this? Section D.1.6.

    • What is the value of the wait_timeout variable in the MySQL server ? mysqladmin variables gives you the value of this

    • Have you tried to run mysqld with --log and check if the issued query appears in the log ?


    Can't connect to [local] MySQL server Error

    A MySQL client on Unix can connect to the mysqld server in two different ways: Unix sockets, which connect through a file in the file system (default ) or TCP/IP, which connects through a port number. Unix sockets are faster than TCP/IP but can only be used when connecting to a server on the same computer. Unix sockets are used if you don’t specify a hostname or if you specify the special hostname localhost.

    On Windows, if the mysqld server is running on 9x/Me, you can connect only via TCP/IP. If the server is running on NT/2000/XP and mysqld is started with --enable-named-pipe, you can also connect with named pipes. The name of the named pipe is MySQL. If you don’t give a hostname when connecting to mysqld, a MySQL client will first try to connect to the named pipe, and if this doesn’t work it will connect to the TCP/IP port. You can force the use of named pipes on Windows by using . as the hostname.

    The error (2002) Can't connect to ... normally means that there isn’t a MySQL server running on the system or that you are using a wrong socket file or TCP/IP port when trying to connect to the mysqld server.

    Start by checking (using ps or the task manager on Windows) that there is a process running named mysqld on your server! If there isn’t any mysqld process, you should start one. See Section 2.4.2.

    If a mysqld process is running, you can check the server by trying these different connections (the port number and socket pathname might be different in your setup, of course):

    shell> mysqladmin version shell> mysqladmin variables shell> mysqladmin -h `hostname` version variables shell> mysqladmin -h `hostname` --port=3306 version shell> mysqladmin -h 'ip for your host' version shell> mysqladmin --socket=/tmp/mysql.sock version

    Note the use of backquotes rather than forward quotes with the hostname command; these cause the output of hostname (that is, the current hostname) to be substituted into the mysqladmin command.

    Here are some reasons the Can't connect to local MySQL server error might occur:

    • mysqld is not running.

    • You are running on a system that uses MIT-pthreads. If you are running on a system that doesn’t have native threads, mysqld uses the MIT-pthreads package. See Section 2.2.2. However, not all MIT-pthreads versions support Unix sockets. On a system without sockets support you must always specify the hostname explicitly when connecting to the server. Try using this command to check the connection to the server:

      shell> mysqladmin -h `hostname` version
    • Someone has removed the Unix socket that mysqld uses (default ). You might have a cron job that removes the MySQL socket (for example, a job that removes old files from the directory). You can always run mysqladmin version and check that the socket mysqladmin is trying to use really exists. The fix in this case is to change the cron job to not remove or to place the socket somewhere else. See Section A.4.5.

    • You have started the mysqld server with the --socket=/path/to/socket option. If you change the socket pathname for the server, you must also notify the MySQL clients about the new path. You can do this by providing the socket path as an argument to the client. See Section A.4.5.

    • You are using Linux and one thread has died (core-dumped). In this case you must kill the other mysqld threads (for example, with the mysql_zap script) before you can start a new MySQL server. See Section A.4.1.

    • You may not have read and write privilege to either the directory that holds the socket file or to the socket file itself. In this case you either change the privilege for the directory / file or restart mysqld so that it uses a directory that you can access.

    If you get the error message Can't connect to MySQL server on some_hostname, you can try the following things to find out what the problem is:

    • Check if the server is up by doing telnet your-host-name tcp-ip-port-number and press Enter a couple of times. If there is a MySQL server running on this port you should get a response that includes the version number of the running MySQL server. If you get an error like telnet: Unable to connect to remote host: Connection refused, there is no server running on the given port.

    • Try connecting to the mysqld daemon on the local machine and check the TCP/IP port that mysqld is configured to use (variable port) with mysqladmin variables.

    • Check that your mysqld server is not started with the --skip-networking option.

    Host '...' is blocked Error

    If you get an error like this:

    Host 'hostname' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'

    this means that mysqld has gotten a lot (max_connect_errors) of connect requests from the host 'hostname' that have been interrupted in the middle. After max_connect_errors failed requests, mysqld assumes that something is wrong (like an attack from a cracker), and blocks the site from further connections until someone executes the command mysqladmin flush-hosts.

    By default, mysqld blocks a host after 10 connection errors. You can easily adjust this by starting the server like this:

    shell> safe_mysqld -O max_connect_errors=10000 &

    Note that if you get this error message for a given host, you should first check that there isn’t anything wrong with the TCP/IP connections from that host. If your TCP/IP connections aren’t working, it won’t do you any good to increase the value of the max_connect_errors variable!

    Too many connections Error

    If you get the error Too many connections when you try to connect to MySQL, this means that there is already max_connections clients connected to the mysqld server.

    If you need more connections than the default (100), you should restart mysqld with a bigger value for the max_connections variable.

    Note that mysqld actually allows (max_connections+1) clients to connect. The last connection is reserved for a user with the process privilege. By not giving this privilege to normal users (they shouldn’t need this), an administrator with this privilege can log in and use SHOW PROCESSLIST to find out what could be wrong. See Section 4.5.6.

    The maximum number of connects allowable to MySQL depends on how good the thread library is on a given platform. Linux or Solaris should be able to support 500-1000 simultaneous connections, depending on how much RAM you have and what your clients are doing.

    Some non-transactional changed tables couldn't be rolled back Error

    If you get the error/warning: Warning: Some non-transactional changed tables couldn't be rolled back when trying to do a ROLLBACK, this means that some of the tables you used in the transaction didn’t support transactions. These non-transactional tables will not be affected by the ROLLBACK statement.

    Typically, this happens when you have tried to create a table of a type that is not supported by your mysqld binary. If mysqld doesn’t support a table type (or if the table type is disabled by a startup option), it will instead create the table type with the table type that most resembles the one you requested, probably MyISAM.

    You can check the table type for a table by doing:

    SHOW TABLE STATUS LIKE 'table_name'. See Section

    You can check the extensions your mysqld binary supports by doing:

    show variables like 'have_%'. See Section

    If you issue a query and get something like the following error:

    mysql: Out of memory at line 42, 'malloc.c' mysql: needed 8136 byte (8k), memory in use: 12481367 bytes (12189k) ERROR 2008: MySQL client ran out of memory

    note that the error refers to the MySQL client mysql. The reason for this error is simply that the client does not have enough memory to store the whole result.

    To remedy the problem, first check that your query is correct. Is it reasonable that it should return so many rows? If so, you can use mysql --quick, which uses mysql_use_result( ) to retrieve the result set. This places less of a load on the client (but more on the server).

    When a MySQL client or the mysqld server gets a packet bigger than max_allowed_packet bytes, it issues a Packet too large error and closes the connection.

    In MySQL 3.23 the biggest possible packet is 16M (due to limits in the client/server protocol). In MySQL 4.0.1 and up, this is only limited by the amount of memory you have on your server (up to a theoretical maximum of 2G).

    A communication packet is a single SQL statement sent to the MySQL server or a single row that is sent to the client.

    When a MySQL client or the mysqld server gets a packet bigger than max_allowed_packet bytes, it issues a Packet too large error and closes the connection. With some clients, you may also get Lost connection to MySQL server during query error if the communication packet is too big.

    Note that both the client and the server have their own max_allowed_packet variable. If you want to handle big packets, you have to increase this variable both in the client and in the server.

    It’s safe to increase this variable as memory is only allocated when needed; this variable is more of a precaution to catch wrong packets between the client/server and also to ensure that you don’t accidently use big packets so that you run out of memory.

    If you are using the mysql client, you may specify a bigger buffer by starting the client with mysql --set-variable=max_allowed_packet=8M. Other clients have different methods to set this variable.

    You can use the option file to set max_allowed_packet to a larger size in mysqld. For example, if you are expecting to store the full length of a MEDIUMBLOB into a table, you’ll need to start the server with the set-variable=max_allowed_packet=16M option.

    You can also get strange problems with large packets if you are using big blobs, but you haven’t given mysqld access to enough memory to handle the query. If you suspect this is the case, try adding ulimit -d 256000 to the beginning of the safe_mysqld script and restart mysqld.

    Communication Error/ Aborted Connection

    Starting with MySQL 3.23.40 you only get the Aborted connection error if you start mysqld with --warnings.

    If you find errors like the following in your error log (see Section 4.9.1):

    010301 14:38:23 Aborted connection 854 to db: 'users' user: 'josh'

    this means that one of the following has happened:

    • The client program did not call mysql_close( ) before exit.

    • The client had been sleeping more than wait_timeout or interactive_timeout without doing any requests. See Section

    • The client program ended abruptly in the middle of the transfer.

    When this happens, the server variable Aborted_clients is incremented.

    The server variable Aborted_connects is incremented:

    • When a connection packet doesn’t contain the right information

    • When the user didn’t have privileges to connect to a database

    • When a user uses a wrong password

    • When it takes more than connect_timeout seconds to get a connect package

    Note that this could indicate that someone is trying to break into your database!

    See Section

    Other reasons for problems with aborted clients/aborted connections.

    • Usage of duplex Ethernet protocol, both half and full with Linux. Many Linux Ethernet drivers have this bug. You should test for this bug by transferring a huge file via ftp between these two machines. If a transfer goes in burst-pause-burst-pause ... mode, you are experiencing a Linux duplex syndrome. The only solution to this problem is switching both half and full duplexing on hubs and switches.

    • Some problem with the thread library that causes interrupts on reads.

    • Badly configured TCP/IP.

    • Faulty Ethernets, hubs, switches, cables... This can be diagnosed properly only by replacing hardware.

    • max_allowed_packet is too small or queries require more memory than you have allocated for mysqld. See Section A.2.8.

    This error occurs in older MySQL versions when an in-memory temporary table becomes larger than tmp_table_size bytes. To avoid this problem, you can use the -O tmp_table_size=# option to mysqld to increase the temporary table size or use the SQL option SQL_BIG_TABLES before you issue the problematic query. See Section 5.5.6.

    You can also start mysqld with the --big-tables option. This is exactly the same as using SQL_BIG_TABLES for all queries.

    In MySQL Version 3.23, in-memory temporary tables will automatically be converted to a disk-based MyISAM table after the table size gets bigger than tmp_table_size.

    Can't create/write to file Error

    If you get an error for some queries of type:

    Can't create/write to file '\\sqla3fe_0.ism'.

    this means that MySQL can’t create a temporary file for the result set in the given temporary directory. (This error is a typical error message on Windows, and the Unix error message is similar.) The fix is to start mysqld with --tmpdir=path or to add to your option file:

    [mysqld] tmpdir=C:/temp

    assuming that the directory exists. See Section 4.1.2.

    Check also the error code that you get with perror. One reason may also be a disk-full error:

    shell> perror 28 Error code 28: No space left on device

    Commands out of sync Error in Client

    If you get Commands out of sync; you can't run this command now in your client code, you are calling client functions in the wrong order!

    This can happen, for example, if you are using mysql_use_result( ) and try to execute a new query before you have called mysql_free_result( ). It can also happen if you try to execute two queries that return data without a mysql_use_result( ) or mysql_store_result( ) in between.

    If you get the following error:

    Found wrong password for user: '[email protected]_host'; ignoring user

    this means that when mysqld was started or when it reloaded the permissions tables, it found an entry in the user table with an invalid password. As a result, the entry is simply ignored by the permission system.

    Possible causes of and fixes for this problem:

    • You may be running a new version of mysqld with an old user table. You can check this by executing mysqlshow mysql user to see if the password field is shorter than 16 characters. If so, you can correct this condition by running the scripts/add_long_password script.

    • The user has an old password (8 characters long) and you didn’t start mysqld with the --old-protocol option. Update the user in the user table with a new password or restart mysqld with --old-protocol.

    • You have specified a password in the user table without using the PASSWORD( ) function. Use mysql to update the user in the user table with a new password. Make sure to use the PASSWORD( ) function:

      mysql> UPDATE user SET password=PASSWORD('your password') -> WHERE user='XXX';

    Table 'xxx' doesn't exist Error

    If you get the error Table 'xxx' doesn't exist or Can't find file: 'xxx' (errno: 2), this means that no table exists in the current database with the name xxx.

    Note that as MySQL uses directories and files to store databases and tables, the database and table names are case-sensitive! (On Windows the databases and tables names are not case-sensitive, but all references to a given table within a query must use the same case!)

    You can check which tables you have in the current database with SHOW TABLES. See Section 4.5.6.

    Can't initialize character set xxx error

    If you get an error like:

    MySQL Connection Failed: Can't initialize character set xxx

    this means one of the following things:

    • The character set is a multi-byte character set and you have no support for the character set in the client.

      In this case you need to recompile the client with --with-charset=xxx or with --with-extra-charsets=xxx. See Section 2.3.3.

      All standard MySQL binaries are compiled with --with-extra-character-sets=complex, which will enable support for all multi-byte character sets. See Section 4.6.1.

    • The character set is a simple character set that is not compiled into mysqld and the character set definition files are not in the place where the client expects to find them.

      In this case you need to:

      • Recompile the client with support for the character set. See Section 2.3.3.

      • Specify to the client where the character set definition files are. For many clients you can do this with the --character-sets-dir=path-to-charset-dir option.

      • Copy the character definition files to the path where the client expects them to be.

    If you get ERROR '...' not found (errno: 23), Can't open file: ... (errno: 24), or any other error with errno 23 or errno 24 from MySQL, it means that you haven’t allocated enough file descriptors for MySQL. You can use the perror utility to get a description of what the error number means:

    shell> perror 23 File table overflow shell> perror 24 Too many open files shell> perror 11 Resource temporarily unavailable

    The problem here is that mysqld is trying to keep open too many files simultaneously. You can either tell mysqld not to open so many files at once, or increase the number of file descriptors available to mysqld.

    To tell mysqld to keep open fewer files at a time, you can make the table cache smaller by using the -O table_cache=32 option to safe_mysqld (the default value is 64). Reducing the value of max_connections will also reduce the number of open files (the default value is 90).

    To change the number of file descriptors available to mysqld, you can use the option --open-files-limit=# to safe_mysqld or -O open-files-limit=# to mysqld. See Section The easiest way to do that is to add the option to your option file. See Section 4.1.2. If you have an old mysqld version that doesn’t support this, you can edit the safe_mysqld script. There is a commented-out line ulimit -n 256 in the script. You can remove the '#' character to uncomment this line, and change the number 256 to affect the number of file descriptors available to mysqld.

    ulimit (and open-files-limit) can increase the number of file descriptors, but only up to the limit imposed by the operating system. There is also a “hard” limit that can only be overrided if you start safe_mysqld or mysqld as root (just remember that you need to also use the --user=... option in this case). If you need to increase the OS limit on the number of file descriptors available to each process, consult the documentation for your operating system.

    Note that if you run the tcsh shell, ulimit will not work! tcsh will also report incorrect values when you ask for the current limits! In this case you should start safe_mysqld with sh!

    PHP mysqli error() Function

    ❮ PHP MySQLi Reference

    Example - Object Oriented style

    Return the last error description for the most recent function call, if any:

    $mysqli = new mysqli("localhost","my_user","my_password","my_db");

    if ($mysqli -> connect_errno) {
      echo "Failed to connect to MySQL: " . $mysqli -> connect_error;

    // Perform a query, check for error
    if (!$mysqli -> query("INSERT INTO Persons (FirstName) VALUES ('Glenn')")) {
      echo("Error description: " . $mysqli -> error);

    $mysqli -> close();

    Look at example of procedural style at the bottom.

    Definition and Usage

    The error / mysqli_error() function returns the last error description for the most recent function call, if any.


    Object oriented style:

    $mysqli -> error

    Procedural style:


    Parameter Values

    connectionRequired. Specifies the MySQL connection to use

    Technical Details

    Return Value:Returns a string with the error description. "" if no error occurred
    PHP Version:5+

    Example - Procedural Oriented style

    Return the last error description for the most recent function call, if any:


    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));


    ❮ PHP MySQLi Reference

    Is this safe to display MySQL query error in webpage if something went wrong?

    A number of answers have pointed out that it's not best practice to display these errors. However, I'm going to focus on your question: is it safe?

    Lets have a look at an example error message. This app is written in Python and Flask:

    enter image description here

    This tells us a few things about the application: it's using SQLite, the app is in , there's a table and a few other things.

    There is no user data here. It doesn't reveal another person's account balance, private messages, anything like that. While it's possible an error message could reveal that, in practice that is rare.

    So how confidential are the application details? The main concern here is making life easier for an attacker. Certain vulnerabilities, such as path traversal and SQL injection are easier to exploit with a bit of information leakage in the error messages. However, they are still exploitable without the information leak - it's just harder work. Restricting error messages does not stop these attacks. It only makes exploitation slightly harder. The change is so minor I don't even consider it when I'm assessing the risk of a vulnerability like SQL injection.

    So, the answer to your question is yes, it is safe. It's not best practice, but in no way is it particularly unsafe.

    answered Sep 30, 2016 at 15:38

    user avatar

    32.7k88 gold badges9292 silver badges130130 bronze badges


    (PHP 5, PHP 7, PHP 8)

    mysqli::$error -- mysqli_error — Returns a string description of the last error

    Return Values

    A string that describes the error. An empty string if no error occurred.


    Example #1 example

    Object-oriented style

    Procedural style

    The above examples will output:

    Error message: Unknown system variable 'a'

    add a note

    User Contributed Notes 7 notes

    information at saunderswebsolutions dot com

    16 years ago

    se (at) brainbits (dot) net

    16 years ago

    callforeach at gmail dot com

    7 years ago

    abderrahmanekaddour dot aissat at gmail dot com

    3 days ago

    asmith16 at littlesvr dot ca

    8 years ago

    information at saunderswebsolutions dot com

    16 years ago


    2 years ago

    To Top

    Error message displaying after execution of a query

    MySQL Error We can display error message in case of an error generated by MySQL query. This meaning full error message gives idea one the problem or bugs in the script. We can print the error message by using mysql function mysql_error(). This function returns the error message associated with most recently executed query. So it is a good idea to check for error before going to next query. We can even add the error number returned by mysql to this error message. This way we can generate a meaningful detail on the bugs on the script. In our student table there is no field as new_field. Here here is the message we will get Note that mysql_error() is deprecated as of PHP 5.5.0 so better to avoid using this function. So if you are using PDO then we can use errorInfo() to display the returned error message from MySQL

    Here is a sample code in PHP using PDO to display record and on failure to display error message.

    In the above code there is an error in sql , there is no column by name no_name. The output will be So to get correct result change the sql part like this . With this you will get desired output.

    Handling PDO errors

    If such error occurs what is to be done ? We have three options to handle in case of errors.

    We can stop the execution of the script. ( Fatal error : stop execution of code )
    We can display warning message ( Warning only, display message and no stoppage of execution )
    Remain silent ( continue to execute and display error message if required )

    Setting the PDO error handling attribute.

    We can use setAttribute to tell how to handle the PDO errors.
    Here is a sample Here is the complete code. Now we have given all the three options but commented two and set the attribute to Silent. You can change the commented status and see how the script is behaving in different setAttribute values.

    It is clear that the above code will generate error message. We can store the error message in a database or we can post ( by mail ) to the programmer about these details.

    Store the error message generated in an sql query or send email >>

    MySQL error query PHP cPanel – Here’s how to fix

    MySQL error query PHP mainly occurs due to incorrect data in the PHP file or due to permissions and ownership error.

    Here at Bobcares, we receive requests to fix the MySQL error query PHP as a part of our Server Management Services for web hosts and online service providers.

    Today, we’ll look at how our Support Engineers fix the MySQL error query PHP.


    How we fix MySQL error query PHP

    There can be many causes for this error message to occur. Fortunately, there are fixes for these different causes as well.

    Now, let’s discuss the causes and see how our Support Engineers fix them.


    1. Incorrect details in the PHP file leads to MySQL error

    The MySQL details in the PHP file must be set correctly. If any data is incorrect then an error will display.

    Recently, one of our customers approached us with an error message ‘MySQL error query PHP’.

    Our Support Engineers were able to confirm that the trouble was with the PHP file in which the customer had set all the database details. The code in the file was as below:

    Here, the customer had set the wrong username under the my_user section present in the code. This caused the error. Our Support Engineers fixed the error by updating the username in the file.


    2. Incorrect Permissions

    Permissions are important for any file to load properly on the server. If there are any incorrect permissions set for any file then it generates an error or the output will not display.

    So, all the files must have the permission of 644. We use the below command to change the permissions.

    Also, the folder in which these files reside must be set with the right permissions. The correct folder permission is 755. We use the below command to change the folder permissions:


    3. Incorrect ownerships

    Similar to permissions, the ownership of the files also plays an important role. The ownership of the file can be either root or the username of the server. However, the right one must be set for the proper functionality of the file.

    We change the ownership of the file using the below command:

    If we need to set the ownership of the file as root then we run the below command:


    4. MySQL server down

    It is very important for the MySQL server to be up and running well. If MySQL is down, then the PHP file will not work that is connected to the database of the server.

    We check the status of the MySQL using the command:

    In case, if the MySQL server is down and displays any error then we restart the MySQL server using the command:

    [Need any further assistance on MySQL error? – We’ll fix it for you]



    In short, the MySQL error query PHP is mainly related to the PHP file. And this can be either caused due to incorrect database details in the PHP file or incorrect permissions or incorrect ownership in files. Today, we saw how our Support Engineers fix this error.


    Never again lose customers to poor server speed! Let us help you.

    Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.


    var google_conversion_label = "owonCMyG5nEQ0aD71QM";


    Leave a Comment