The following function execute a query and return an associative array if is needed.
<?php /** * Execute a Query and return an associative Array * * @param string $sql * @param resource $link * @param bool $getArray * @return boolean/array */ function executeQuery($sql, $link, $getArray = true) { if (!is_string($sql)) return false; $result = mysql_query($sql, $link); if (!$result) exit('Error: ' . mysql_error()); else { if ($getArray) { $arrTemp = array(); if (mysql_num_rows($result) != 0) { while ($row = mysql_fetch_assoc($result)) $arrTemp[] = $row; } else return array(); return $arrTemp; } } return true; } ?>

0 Comments.