mysql_real_escape_string() and mysql_get_server_info(): Access denied for user ”@’127.0.0.1′ (using password: NO)

Today I transferred my WordPress website to a new web host running a more recent version of php (5.5.0) than my previous web host. I transferred my website and I started getting the error massages below on some plugins that I wrote myself.

Warning: mysql_real_escape_string(): Access denied for user ”@’127.0.0.1′ (using password: NO) in …

Read More

I have done some research, but all I found was that I don’t have a link to mysql established (which I believe is false, since the WordPress database class does that for us).

Any ideas on how I can solve the issue? Below you can find how I connect to the database in my plugins.

function init() 
{
    $this->database = $GLOBALS['wpdb'];
    $this->prefix = $GLOBALS['table_prefix'];   

    if(version_compare(mysql_get_server_info(), '4.1.0', '>=')) 
    {
        if (!empty($this->database->charset))
            $this->charset_collate .= sprintf(' DEFAULT CHARACTER SET %s', $this->database->charset);

        if (!empty($this->database->collate))
            $this->charset_collate .= ' COLLATE ' . $this->database->collate;
    }   

    register_activation_hook(__FILE__, array($this, 'install_database_tables'));
}

Related posts

Leave a Reply

1 comment

  1. After doing some more research and looking at the wp-db.php file, I have found that you need to replace your functions bu the following:

    global $wpdb;
    
    //mysql_get_server_info() becomes
    $wpdb->db_version() = 'YOUR_SQL_SERVER_INFO';
    
    //mysql_real_escape_string() becomes
    $wpdb->_real_escape('some_string') = 'ESCAPED_STRING';