Skip to:

mysql_query() OR $bbdb->get_results() ?

  • Hi,

    I currently have an API problem fixing a plugin. Using mysql_query() will result in errors on some boards so I wanted to change this using $bbdb->get_results(). This works, but mysql_fetch_array will error things up now. What do I need to change to make this work correctly?

    Current code (without using $bbdb->get_results()):

    $r = mysql_query("SELECT * FROM $bbdb->menu
    WHERE set = 'inactive' ORDER BY order ASC");
    while($rw = mysql_fetch_array($r))

Viewing 15 replies - 1 through 15 (of 15 total)
  • Or use:

    $bbdb->query ??



    Stick with the ezSQL format… it’ll be much easier.

    Something like this (using foreach instead of while):

    $query = "SELECT * FROM $bbdb->menu
    WHERE set = 'inactive' ORDER BY order ASC";
    $r = $bbdb->get_results( $query );

    foreach( $r as $rw ) {
    // now mess with $rw
    echo $rw->database_row . "<br>n";

    Something that might be helpful would be to browse the source of the ezSQL class in /wp-includes/wp-db.php

    The latest from Justin Vincent, the author

    The version used in bbPress and WordPress

    It might help you… you’d be able to see where mysql_query is begin used, and how to use the ezSQL format best.

    I think the reason you’re running into problems with mysql_fetch_array is because it’s already used.

    Not sure on that one though… I would have to check.

    Also, what might cause an error: $bbdb->query will not return anything at all. $bbdb->get_results needs to be used for multi-dimensional array data, $bbdb->get_row or $bbdb->get_col need to be used for single array data, and $bbdb->get_var needs to be used for non-array/string data. $bbdb->query is used for inserting data, the others are used for retrieving it.

    Someone correct me if I’m wrong, but I’m pretty positive that’s how it goes.

    ezSQL is lovely. It certainly takes the pain out of MySQL data manipulation.

    So I guess that makes the answer to your question “Neither.” $bbdb->get_results should do the trick.

    And sorry for the screed. :D

    -double post-


    Wheren’t you the guy that fixed (or claimed to have fixed) this particulair error I had with the bbMenu plugin?

    Thinking… yeah you where it, you said you fixed it using $bbdb->get_results. So I replaced all mysql_query() with it, but this caused an error with the mysql_fetch_array. So what more did you change? Cause I can’t seem to fix it :( I can hardly program, so some help plz :)




    Give me a day or so and I’ll work on it. I’ve got about three jobs going at the moment.

    Okay okay, 1 day :) (just kidding)

    Im having the same issue with this plugin. I switched all my tags to $bbdb->get_results and it stoped the errors. But i never got this plugin to work i just got the errors gone. It never created the table. I manually created the table but i dont know how to populate it with the neccessary information needed. Also since it never created the table im assuming thats why i never saw a admin link to it in my admin control panel. Does anyone know how to manually populate a table? Or can you make a .sql file that manually creates and fill this table for me?

    Thank you.

    @ MaryJane download and use phpMyAdmin. It gives you acces to you database. You still need to know how to make/use SQL queries though :(

    @Box, dude had any time to help me out with the bbMenu plugin thingy? I want to fix this issue before I start with the next version (using jquery and fixing alot of bugs)


    I dont need to download phpmyadmin. I already have it with my hosting. Thats what i used to make the table to bein with. Since i cant get this to work without a bunch of errors ive disabled it until a better solution is figured out.



    @Null – Working on it…

    Don’t lose hope :)

    Sorry about the “day or so”…



    The new changes have been made:

    I think that should cover the problems. I took the liberty of changing other things as well… hope you don’t mind. I removed some redundancies in the CSS, and changed some little code things.

    There’s the modified bbmenu.php file, as well as the diff file to make it a little easier for you to see what I changed. If you cant make sense of the diff there are diff file viewers that color the text and make it more human-readable.

    Testing this tomorrow after work…. nah after diner after work :)

    Thx for the help mate!


    ps. how to open a .diff?? (windows machine)

    You need something like TortoiseSVN that’ll let you apply patches to files.

    I have that TortoiseSVN installed, still need to figure out how to let this update the trac aswell :)

    Hmmm got this error:

    Warning: Invalid argument supplied for foreach() in /home/sites/site116/web/bbpress/my-plugins/bbmenu.php on line 390

    the foreach:

    foreach( $r1 as $rw ) {


Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.
Skip to toolbar