Skip to content

Instantly share code, notes, and snippets.

@jxxe
Last active September 25, 2020 21:21
Show Gist options
  • Save jxxe/52105f9adbdedbfbe8af8a52c0b540b9 to your computer and use it in GitHub Desktop.
Save jxxe/52105f9adbdedbfbe8af8a52c0b540b9 to your computer and use it in GitHub Desktop.
Not all servers run the latest version of PHP or have enabled all the packages. This small replacement saved me a lot of frustration with my web host.
<?php
// Replace
$data = $query->fetch_all(MYSQLI_ASSOC);
// With
$rows = [];
while ( $row = mysqli_fetch_assoc($query) ) {
$rows[] = $row;
}
$data = $rows;
// Or Even, Define
function fetch_assoc($query) {
$rows = [];
while ( $row = mysqli_fetch_assoc($query) ) {
$rows[] = $row;
}
return $rows;
}
// And Use
$data = fetch_assoc($query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment