0

I'm using Amazon Web Services (AWS) Wordpress which uses Bitnami.

I've created a test template, wrote a SELECT statement to test pulling data from the database, uploaded the template, selected the template for a page, and previewed it. Here are the results.

WordPress database error: [SELECT command denied to user 'bn_wordpress'@'localhost' for table 'wp_comments']

SELECT * FROM wp_.wp_comments WHERE comment_ID = 2

This is the statement from the template PHP file.

$id = "2";
$sql = "SELECT * FROM $wpdb->prefix.wp_comments WHERE comment_ID = $id";
$results = $wpdb->get_results($sql);

foreach( $results as $result ) {

    echo $result->name."<br>";

}

The database for the Bitnami Wordpress install is using phpMyAdmin and the database name is bitnami_wordpress and the table is named wp_comments.

I have selected both the database bitnami_wordpress and the wp_comments table and checked their privileges using the phpMyAdmin GUI. I opened up "Edit Privileges" to double check and everything is selected.

Type --> wildcard: bitnami_wordpress

Privileges --> ALL PRIVILEGES

Grant --> Yes

All I'm trying to do is figure out how to pull data from the database and place it on pages so I can develop some templates for my WordPress site. Any help is appreciated.

1
  • Does the user bn_wordpress have ALL the Privileges? Run this SELECT * FROM information_schema.USER_PRIVILEGES and see or use the PHPMyAdmin view to verify. Nov 26, 2017 at 7:41

1 Answer 1

3

This is something that has thrown me off in the past. You actually see the error that talking about the Privileges, but the actual error is that the database doesn't exist!

You are searching for database name wp_ where there is only bitnami_wordpress.

$sql = "SELECT * FROM bitnami_wordpress.wp_comments WHERE comment_ID = $id";
1
  • Thanks. I had tried $wpdb->bitnami_wordpress.wp_comments but obviously that didn't work. I didn't realize I could just remove $wpdb and call it directly. Thank you again.
    – Matt
    Nov 26, 2017 at 21:49

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.