• Resolved patdundee

    (@patdundee)


    Hi Guys
    I have been running custom mysql queries for a while now and since upgrading to WP 3.92 and PHP V 5.5.9-1 i have issues.

    SInce the changes my sql queries are not working. I understand that perhaps 3.92 is now using mysqli instead. However I am still getting an issue

    for example I have
    $res=mysqli_query("select * from counties ORDER BY County ASC",MYSQLI_USE_RESULT);

    The table name is in the WP database

    but i get this error when running the above

    Warning: mysqli_query() expects parameter 1 to be mysqli, string given
    I beleive it needs the name of the db connection but i have no idea what that is.

    Any ideas or help would be greatly appreciated

    Many thanks
    Patrick

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter patdundee

    (@patdundee)

    I Have found a temporary solution

    In wp-db.php find the lines below (around line 588) and comment them out.

    `if ( function_exists( ‘mysqli_connect’ ) ) {
    if ( defined( ‘WP_USE_EXT_MYSQL’ ) ) {
    $this->use_mysqli = ! WP_USE_EXT_MYSQL;
    } elseif ( version_compare( phpversion(), ‘5.5’, ‘>=’ ) || ! function_exists( ‘mysql_connect’ ) ) {
    $this->use_mysqli = true;
    } elseif ( false !== strpos( $GLOBALS[‘wp_version’], ‘-‘ ) ) {
    $this->use_mysqli = true;
    }
    }`

    You should be using the $wpdb methods instead of the mysqli_* ones.

    So, for your query you’d use something like:

    $results = $wpdb->get_results ("SELECT * FROM counties ORDER BY County ASC");

    That’s all that you’ll need to change, and you’ll keep all of your DB interaction working through the known WPDB functions.

    Thread Starter patdundee

    (@patdundee)

    Hi
    Many thanks for that 🙂
    I have now tried that in this statement but get the following error

    `$result=$wpdb->get_results(“SELECT County FROM counties”);
    while ($row=$result->fetch_assoc()) {
    echo $row[‘County’].'<br>’;
    }`

    Fatal error: Call to a member function fetch_assoc() on a non-object

    Suggest that you try:

    $result=$wpdb->get_results("SELECT County FROM counties");
     foreach($results as $row) {
      echo $row['County'].'<br>';
     }

    Thread Starter patdundee

    (@patdundee)

    This is fun (not 🙂

    It now throws up

    Fatal error: Cannot use object of type stdClass as array

    the line in question it refers to is the
    echo $row['County']."<br>";

    Go back and re-read what I posted in your other thread. That gives you exactly what you need to use.

    http://wordpress.org/support/topic/what-is-the-wp-data-connection-name?replies=3

    Thread Starter patdundee

    (@patdundee)

    Many thanks 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘mysqli issue’ is closed to new replies.