Strict Standards: mysqli_next_result() Error with mysqli_multi_query
Issue:
Using mysqli_multi_query() triggers a "Strict Standards" error related to mysqli_next_result().
Solution:
To resolve this issue, use the following code:
do{} while(mysqli_more_results($db) && mysqli_next_result($db));
Explanation:
The Strict Standards error occurs because mysqli_more_results() must be called to check if mysqli_next_result() should be used. The provided code snippet ensures that mysqli_next_result() is only called if there is another result set.
Considerations:
Enhancements:
For a more robust approach, consider the following code snippet:
if(mysqli_multi_query($db,$querystring)){ do{ $cumulative_rows+=mysqli_affected_rows($db); } while(mysqli_more_results($db) && mysqli_next_result($db)); } if($error_mess=mysqli_error($db)){echo "Error: $error_mess";} echo "Cumulative Affected Rows: $cumulative_rows";
This code snippet:
Additional Notes:
For users unfamiliar with mysqli_multi_query(), here is a versatile code snippet that handles queries with or without result sets:
while((isset($multi_query) && (next($queries) && mysqli_more_results($mysqli) && mysqli_next_result($mysqli))) || (!isset($multi_query) && $multi_query=mysqli_multi_query($mysqli,implode(';',$queries)))){ echo "<br><br>",key($queries),": ",current($queries); // display array pointer key:value if($result=mysqli_store_result($mysqli)){ while($rows=mysqli_fetch_assoc($result)){ echo "<br>Col = {$rows["Col"]}"; } mysqli_free_result($result); } echo "<br>Rows = ",mysqli_affected_rows($mysqli); // acts like num_rows on SELECTs }
This code snippet:
The above is the detailed content of How to Fix \'Strict Standards: mysqli_next_result() Error\' with mysqli_multi_query()?. For more information, please follow other related articles on the PHP Chinese website!