Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing @mysql_fetch_array for php7 upgrade

Tags:

php

php-7

I'm trying to migrate a Wordpress site. My new host uses PHP7, and there's a plugin that calls @mysql_fetch_array which is a function that has been removed from PHP7.

This is the function call within its control loop:

while( $row = @mysql_fetch_array( $result) ) {
    $newSlider = array();
    $newSlider['name'] = $row['title'];
    $newSlider['value'] = $row['alias'];
    $toReturn[] = $newSlider;
}

I did a print_r of the $result Object, and this was the result:

mysqli_result Object
(
    [current_field] => 0
    [field_count] => 2
    [lengths] => 
    [num_rows] => 2
    [type] => 0
)

Is there a drop-in replacement function for @mysql_fetch_array that works with PHP7?

like image 212
bobbyh Avatar asked Oct 26 '25 14:10

bobbyh


1 Answers

It appears the $result has been migrated already to use mysqli. If this is the case, then the function mysqli_fetch_array is a drop in replacement for mysql_fetch_array.

like image 199
Adder Avatar answered Oct 29 '25 04:10

Adder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!