WordPress.org

Forums

[resolved] Is there an equivalent to mysql_fetch_assoc using $wpdb (2 posts)

  1. AronMS
    Member
    Posted 2 years ago #

    Is there an equivalent to mysql_fetch_assoc or while mysql_fetch_array using the $wpdb class?

    For example:

    while ($row = mysql_fetch_assoc($results)){
        // Do code to process db results here.
    }

    How would I write this using the $wpdb class?

  2. bcworkz
    Member
    Posted 2 years ago #

    As you know, mysql_fetch_assoc() processes the results returned by mysql_query(). $wpdb class methods typically return results of a query to the wordpress database similar to what mysql_query() would do. $wpdb class methods do not process such results as mysql_fetch_assoc() would do, so there is no true equivalent.

    What I usually do with the results from $wpdb queries that is similar to your example is:

    foreach ($results as $row) {
        // Do code to process db results here.
    }

    Some $wpdb methods have an option to return results in various forms. I now wonder if one of these would be compatible to pass to mysql_fetch_assoc(). Something to toy with when I'm bored!

Topic Closed

This topic has been closed to new replies.

About this Topic