Home / Programming / php / How can I load a mysql query into a hash in php?
How can I load a mysql query into a hash in php?
Last updated: 02/07/2012
Often times it's nice to query a database, and pull back the results into a hash, keyed by one of the fields in the table. This function does just that. Just pass it a database link, SQL statement, array reference (to store the resulting hash, and the "key" field you want to use for the hash key. The function will execute the query and put the resulting hash into the all_hash array you passed in.
function select_sql_hash ($link,$sql,&$all_hash,$key) {