Title: SQL query on bookings database
Last modified: August 20, 2016

---

# SQL query on bookings database

 *  Resolved [sonnensegler](https://wordpress.org/support/users/sonnensegler/)
 * (@sonnensegler)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/sql-query-on-bookings-database/)
 * Hey there,
    I need to run a simple SQL query on the bookings database wp_em_bookings
   of the plugin Events Manager. I am using the newest version of both WordPress
   and the plugin.
 * Say, I want to check the booking status of a specific user and echo it:
 *     ```
       <?php
       global $wpdb;
       global $EM_Event;
       global $current_user;
       get_currentuserinfo();
       $userid = $current_user->ID;
       $eventid = $EM_Event->id; 
   
       $mybookings = $wpdb->get_results("SELECT * FROM $wpdb->em_bookings WHERE event_id = $eventid AND person_id = $userid");
   
       foreach ($mybookings as $mybooking) {
       	echo $mybooking->booking_status;
       }
       ?>
       ```
   
 * But whatever I’m using, either $wpdb->query or get_results, I can’t get my query
   to access the database tables. I tried to replace $wpdb->em_bookings with ‘$wpdb-
   >prefix . EM_BOOKINGS_TABLE;” (found this in another forum post), but still no
   result. I tried adding the output_type for an array, nothing.
 * I even replaced all variables with actual numbers, id’s existing in the table.
   Nothing.
 * If I output only the variables $userid and $eventid from above, it’s giving me
   the right numbers. If I run a SELECT query on a normal wordpress database table,
   e.g. wp_links, it’s working as well.
 * Do I need to set a different global variable??
 * What am I doing wrong?
 * Help greatly appreciated!
 * Thanks, Christiane

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/sql-query-on-bookings-database/#post-2251778)
 * are you checking for sql errors?
 *  Thread Starter [sonnensegler](https://wordpress.org/support/users/sonnensegler/)
 * (@sonnensegler)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/sql-query-on-bookings-database/#post-2251779)
 * Yes, I finally did within SequelPro (and with Firebug and activated php error
   logging) and that saved me a lot of time 😉
 * Fortunately I got it working with
 * $results = $wpdb->get_results(“SELECT * FROM wp_em_bookings WHERE event_id = 
   $eventid AND person_id = $userid “, OBJECT_K);
 * (the WordPress tutorial for interfacing with the database tells you to leave 
   out the prefix)
 * and then working with that array. Plus I had to add
 *  define(‘WP_USE_THEMES’, false);
    require($_SERVER[‘DOCUMENT_ROOT’].’/wp-blog-
   header.php’);
 * in the header of my file since my function doesn’t get all the globals from WordPress
   headers.
 * A client of ours needs a possibility to cancel an event straight away without
   ever reserving for it, so I had to try a little with database and booking status.
 * I solved the core changing problem by using a custom placeholder for this special
   button.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘SQL query on bookings database’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=3550347)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * 2 replies
 * 2 participants
 * Last reply from: [sonnensegler](https://wordpress.org/support/users/sonnensegler/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/sql-query-on-bookings-database/#post-2251779)
 * Status: resolved