PHP Function that contains SQL query not working -
i'm attempting put function perform sql queries part of code cleanup i'm doing. query works outside of function, inside function no results. here's applicable code:
<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> <html> <body> <?php header("cache-control: no-cache, must-revalidate"); require_once'../connect.php'; function callquery($select,$from,$where){ $pull=array(); $query="select ".$select." ".$from." ".$where; $run=sqlsrv_query($conn,$query); while($result=sqlsrv_fetch_array($run,sqlsrv_fetch_assoc)){ $results=var_dump($result); } return $query; return $results; } echo callquery("hdcasenum","hdcase","hdcasenum='8818'"); ?> </html></body> the code test setup concept down.
edit trying accomplish:
function callquery($select,$from,$where,$conn){ $results=array(); if($where){$where="where $where";} $query="select ".$select." ".$from." ".$where; $run=sqlsrv_query($conn,$query); while($result=sqlsrv_fetch_array($run,sqlsrv_fetch_assoc)){ array_push($results,$result); } return $results; } i pass in columns, table(s) , filters , spits out multidimensional array of results. keeps me having retype sqlsrv functions on , on again.
pass $conn 1 parameter of function too.
Comments
Post a Comment