mysqli - Is there a functional equivalent to mysqli_fetch_all in PHP 5.2? -
so, total n00b @ php (and back-end programming in general), never less decided wanted build functioning database users search client-side th final project first web dev class.
anyway, made site , database on localhost, , though took while, got functioning perfectly. when tried move webhost, however, started breaking because, unbeknownst me, webhost using php 5.2. i've been able rig else functioning solutions of dubious security (i know, know, i'm desperate, , there's fake data on here anyway), 1 thing can't find fix mysqli_fetch_all(). call undefined function mysqli_fetch_all() error.
i'm using search functionality: when search user, function takes rows matching information , puts in array, , @ end, result arrays merged single array returned. did way search criteria not entered ignored , not return error (null has been bane of existence entire project).
the site can viewed @ http://webinfofinal.webatu.com/profiles.html see i'm working , code below. suggestions? i've tried other fetch functions, return first matching row.
if ($firstname != null){ $result2 = mysqli_query($con, "select displayname , firstname , lastname , email , age , classification , major , faveanimes a2097702_fac.members firstname = '$firstname' "); $query2 = mysqli_fetch_all($result2,mysqli_assoc); $search = array_merge_recursive($search, $query2); } if ($lastname != null){ $result3 = mysqli_query($con, "select displayname , firstname , lastname , email , age , classification , major , faveanimes a2097702_fac.members lastname = '$lastname' "); $query3 = mysqli_fetch_all($result3,mysqli_assoc); $search = array_merge_recursive($search, $query3); } if ($email != null){ $result4 = mysqli_query($con, "select displayname , firstname , lastname , email , age , classification , major , faveanimes a2097702_fac.members email = '$email' "); $query4 = mysqli_fetch_all($result4,mysqli_assoc); $search = array_merge_recursive($search, $query4); } if ($age != null){ $result5 = mysqli_query($con, "select displayname , firstname , lastname , email , age , classification , major , faveanimes a2097702_fac.members age = '$age' "); $query5 = mysqli_fetch_all($result5,mysqli_assoc); $search = array_merge_recursive($search, $query5); } if ($classification != null){ $result6 = mysqli_query($con, "select displayname , firstname , lastname , email , age , classification , major , faveanimes a2097702_fac.members classification = '$classification' "); $query6 = mysqli_fetch_all($result6,mysqli_assoc); $search = array_merge_recursive($search, $query6); } if ($major != null){ $result7 = mysqli_query($con, "select displayname , firstname , lastname , email , age , classification , major , faveanimes a2097702_fac.members major = '$major' "); $query7 = mysqli_fetch_all($result7,mysqli_assoc); $search = array_merge_recursive($search, $query7); } if ($faveanimes != null){ $result8 = mysqli_query($con, "select displayname , firstname , lastname , email , age , classification , major , faveanimes a2097702_fac.members faveanimes = '$faveanimes' "); $query8 = mysqli_fetch_all($result8,mysqli_assoc); $search = array_merge_recursive($search, $query8); } if ($search != null){ echo "<html>"; echo "<head>"; echo"<title> anime club search results | web info final project </title>"; echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"webinfofinal.css\">"; echo "</head>"; echo "<div class=\"content\" style=\"width:50%; margin-left:-20%;\">"; echo "<div class=\"header\">"; echo "<p></p><p>your search results below. </p>"; echo "</div>"; echo "<pre>"; print_r($search); echo "</pre>"; echo "<p>end of results. <a href=\"profiles.html\">search again?</a></p>"; echo "<a href=\"login.html\"><input type='button' value='update profile' id='updateprofile'></a>"; echo "<a href=\"logout.php\"><input type='button' value='log out' id='logout'></a>"; echo "</div>"; echo "</html>"; }
no, fetch_all
method available if use mysqlnd library.
it possible compile mysqlnd php 5.2 (see http://blog.ulf-wendel.de/2007/php-compiling-mysqlnd-with-php-525360/) if web hosting provider isn't ready upgrade current version of php, doubt they'll install mysqlnd you.
you can convert code pdo, supports pdostatement::fetchall().
or can code own fetch_all
function mysqli, not hard:
function fetch_all($result) { $rows = array(); -- old array syntax still needed in php 5.2 while ($row = $result->fetch_assoc()) $rows[] = $row; return $rows; }
i recommend find different web host. php 5.2 officially end-of-life, , there may security vulnerabilities fixed in later version of php, not in 5.2. see http://php.net/eol.php
Comments
Post a Comment