WordPress.org

Forums

[resolved] unable to access wpdb (3 posts)

  1. rajlaksh
    Member
    Posted 1 year ago #

    I'm using wp 3.9.1 on my windows PC

    its able to access wp-load.php and able to run queries.

    But i use that in website its unable to access database. and got these error.

    Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in /home/public_html/ajx.php on line 13
    
    Warning: mysql_real_escape_string(): A link to the server could not be established in /home/public_html/ajx.php on line 13
  2. rajlaksh
    Member
    Posted 1 year ago #

    My ajx.php located in root of wordpress where wp-load.php located.

    my PC and Web Site has same version of MySQL . php 5.4 in PC and php 5.5 in Web Site.

    Here is code of my file

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    if(empty($_REQUEST['term'])){
    echo "[ ]";
    die();
    }
    else {
    include('wp-load.php');
    global $wpdb, $kommiku, $series;
    
    $autocomplete_value = mysql_real_escape_string($_REQUEST['term']);
    $table = $wpdb->prefix."comic_series";
    
    $select = "SELECT * FROM <code>".$table."</code> WHERE title COLLATE UTF8_GENERAL_CI LIKE '$autocomplete_value%' ORDER BY <code>title</code> limit 20";
    $query = mysql_query($select);
    
    if($query === FALSE) {
        die(mysql_error()); // TODO: better error handling
    }
    while($row = mysql_fetch_array($query))
    {
    $results[] = array('title' => $row['title'] , 'slug' => $row['slug'] , 'cat' => $row['categories'] , 'img' => $row['img'] );
    }
    echo json_encode($results);
    
    die();
    }
    ?>

    That code working fine in My PC with 3.9.1 version . but in Website got that error.

    warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO)

  3. rajlaksh
    Member
    Posted 1 year ago #

    I changed whole query to $wpdb. not its working.

Topic Closed

This topic has been closed to new replies.

About this Topic