Did the WordPress default database connection allow for the use of mysql_query() in years gone by? If so, at what point did this end? Am I assuming correctly that it has to do with the WordPress database object?

Background: Many years ago, I wrote a custom template for a WordPress client that involved importing an XML feed into the database and showing it on WordPress pages. I kept copious notes, but only on the trouble areas, and the database connection wasn't one of those. The client moved on, but is now back with an error in that old, old code. I can fix it, but my client is the curious sort and may want specifics on what changed.

The error is Warning: mysql_query(): Access denied for user 'root'@'localhost' (using password: NO) in /Address to WordPressTemplate.php on line 38. There is no connection string that I can find, so I'm assuming that this query was using the default WordPress database connection.

  • Please edit your question and add in the relevant code (ie, the code around line 38 where the error is thrown). This will make it easier for us to help out.
    – Pat J
    Feb 27, 2018 at 19:24
  • 1
    Access denied for user 'root'@'localhost' (using password: NO) is one of the more explaining mysql errors (unlike "using password: YES" ..) - The given password is incorrect
    – kero
    Feb 27, 2018 at 19:45
  • Is it possible for this error to be thrown if there is no connection string at all? That is, if mysql_query() is used without there being a connection string. I say this, because I'm just not finding the connection. So, I assumed mysql_query() was using the WordPress connection, which is working for the rest of the site. Feb 27, 2018 at 20:26

1 Answer 1


WordPress still has mysql_query() in its codebase (as of February 27, 2018).

mysql_*() was deprecated in PHP 5.5.0 and removed in PHP 7.0.0. Since WordPress still supports PHP 5.2 (for reasons beyond understanding), it needs to support both mysql_*() and mysqli_*(), WordPress will use mysqli_query() when available ( PHP > 5.3.0 ) and fallback to mysql_query().

If it's the WordPress $wpdb object that is using mysql_query() it means you're running on PHP 5.2.x, which you really should upgrade. If you're certain you're on PHP 5.3 or greater, then there's some other code that's using the old mysql_query().

Although based on the error, it looks like it's a problem with the permissions in your SQL database.

  • That information will be beneficial in pushing for a PHP update! One of the things that happened when the client moved to different website management is that quite a lot of things weren't updated. I gave my opinion at the time and then backed out of the fray. Feb 27, 2018 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.