Support » Plugin: Contact Form DB » Query utilizing wpdb->get_results() instead of mysql query?

  • Just wondering if there is an example around of utilizing wpdb->get_results instead of the mysql Query SELECT in your examples.

    I know it’s a pretty funky db thing you are doing. So any shove in the right direction would be greatly appreciated.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Michael Simpson


    You can use wpdb->get_results with the same SQL that the plugin uses. The plugin does not use wpdb->get_results so it can instead use an unbuffered query so that performance is still OK when there are very large numbers of rows being returned by the query.

    I’m not sure what you are wanting to do, but if you are just trying to get data from a form by writing your own PHP, then have a look at the CFDBFormIterator API.

    Hey guys thanks for the responses.

    @michael yeah after some further reading I found it wasn’t the backticks that were my issue.

    I wrote a separate plugin to be able to email out a report of the data stored by your plugin monthly using wp_cron, it emails out a table of the results similar to the shortcodes as well as an attached csv file.

    I wasn’t too overly worried about the performance of it. Because I wasn’t expecting hundred of records and I am also splitting the records up based on timestamp.

    While I was in the process of researching I actually put it in as a feature request on your site. I kept mine as a separate plugin rather than editing anything you had going on in your plugin.

    BTW the link you sent is throwing a 500

    Thanks again

    Plugin Author Michael Simpson


    Looks like my whole site is down. Thanks for letting me know.

    Here is the content of that link:

    If you want to programatically access a form’s data, follow this example code.

    // Email all the Mike's
    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
    $exp = new CFDBFormIterator();
    $exp->export('my-form', array('show' => 'name,email', 'search' => 'Mike'));
    while ($row = $exp->nextRow()) {
        wp_mail($row['email'], 'Hello ' . $row['name], 'How are you doing?');


    • The second argument to “export” (the array) is optional. But use it to set options just as you would for shortcodes. The example above shows how to use the ‘search’ shortcode option to limit entries (rows) to only those that have “mike” in them.
    • Be sure to iterate over all of the data event if you do not use it (i.e. don’t ‘break’ out of the while loop.). This is related to the fact that mysql_unbuffered_query call is being used behind the scenes.

    This worked out for me. Thanks Michael. I see how there is ‘search’ and filter. Let’s say I wanted to get the submit_time for the last month based on timestamp. Does the filtering support this?

    Thanks again for this awesome plugin.

    Doing a quick filter based on what’s in the shortcode examples I received an error.

    Looked through your code and saw support for comparisons in your filter classes.

    Maybe I am implementing it incorrectly. I figured it was a pretty simple one.

    $exp->export( $form_name, array('filter'=>"submit_time>=$time"));

    Actually realized I was going against the database submit_time not the Submitted variable within the object.

    But I did notice that it wouldn’t compare the time stamps properly. So I made a slight change to compare the values as (int) for now.

    My time was 1307123123 for example vs your time of 1307123123.2343 and it wouldn’t compare the 2 values properly.

    Plugin Author Michael Simpson


    What change did you did make to get it to work?

    Plugin Author Michael Simpson


    I just fixed some code to filter properly on submit_time. I’ll push a version 1.8.8 with that shortly.

    Nice I actually just adjusted your code slightly just to get my lil plugin out the door. But that’s great. Once you push an update out I’ll grab it and see how it goes.

    Oh also I just (int) instead of float in the comparison parser you had going on. It seemed to do the trick in my initial testing.

    Hey Michael, noticed that when I tried to hide “submit_time” or “Submit Time” the column always showed for me. Also I have a plugin that utilizes your plugin that we are testing internally in our shop. Wanted to know if you wanted to take a look at it before I release it. I have a few things I need to do to it before it’s ready for primetime.

    I figured that because I am relying on your plugin so heavily for my plugin; I’d see if you wanted to take a look at it. Just lemme know and I can share a dropbox with you or email whatever.

    Plugin Author Michael Simpson


    Yes, I’m interested to see what you are doing and what parts of the plugin you are depending on. Maybe we can do a call or WebEx and you can walk me through your plugin and any issues you are having. Looking at your profile, we are both on the east coast time zone. When might you wan to talk?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Query utilizing wpdb->get_results() instead of mysql query?’ is closed to new replies.