Just hacked together the following function for querying a MySQL database and returning the results as a multi-dimensional array. Enjoy…
[code=php]<?php
#
# query_db(query_string [, connection])
#
# Sends query to MySQL DB and returns results in array with the structure:
# array[row_num][‘col1’]=value
# array[row_num][‘col2’]=value
# etc….
#
# Created 2004/08 by Charles Reace
#
# NOTE: must connect to desired DB before calling
# returns 0 on any failure
#
function query_db($query, $connx=””)
{
switch($connx)
{
case “”:
$result = mysql_query($query);
if(!$result) { return(0); }
break;
case 2:
$result = mysql_query($query, $connx);
if(!$result) { return(0); }
break;
default:
return(0);
}
$ix = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
foreach($row as $key => $value)
{
$arr[$ix][$key] = $value;
}
$ix++;
}
return($arr);
}