WordPress – mysql_query(): Access denied for user ‘www-data’@’localhost’ (using password: NO) error on production server

I’m getting a warning message when I enable wordpress debug mode.

Warning: mysql_query(): Access denied for user ‘www-data’@’localhost’
(using password: NO) in
/var/www/html/blog/wp-content/plugins/test/manage_registrations.php on
line 46

Read More

Warning: mysql_query(): A link to the server could not be established
in /var/www/html/blog/wp-content/plugins/test/manage_registrations.php
on line 46

PHP code:

$extrawhere1=" order by id desc LIMIT $start, $limit";
$sqlSearch="select * from visa where 1=1 $extrawhere $extrawhere1";
$query="select * from visa where 1=1 $extrawhere order by id desc ";
$_SESSION['export_data']=$query;

$num=@mysql_num_rows(mysql_query($query));
$select_product=mysql_query($sqlSearch);

I tried using

$select_product=$wpdb->query($sqlSearch);

But i’m still getting error message. This error is only appearing on production server and not on local server.

Related posts

2 comments

  1. Write these 2 lines at top of the file to check for any error

    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 1);
    

    also check your config.php for db connection (correct or not)

    May be load on your db has increased to the point where connections were unable to proceed further.

  2. Check your database credentials. It seems like you are using an incorrect password. Or try:

    $wpdb->query('select * from ..'); 
    

    Another possibility is you are using a mysqli connection and and trying to execute mysql_query.

    Or try:

    $query = $wpdb->get_results("SELECT * FROM ...", ARRAY_A);
    print_r($query);
    foreach($query as $row)
    {
    // do stuff with $row here.
    }
    exit;
    

Comments are closed.