This function combines the use of three functions, two of which have been described on later posts.
Connect to a MySQL database using php with error reporting
Displaying array contents in an easy to use format using php
What makes this php query function different from most is the error reporting. If a error does occur with your statement the script is stopped and a nicely formatted explanation of the error is displayed. This has saved me hours of debugging and can be combined with other error reporting scripts to allow for better running of services and systems.
function query_array($query) {
if (!$result = mysql_query($query)) {
die("Sorry there has been a problem - " . mysql_error());
} else {
while ($array = mysql_fetch_array($result,MYSQL_ASSOC)) {
$return[] = $array;
}
return ($return);
}
}
Download the complete script including the other two functions here
