I have mySQL table:
CREATE TABLE config (
name varchar(255) collate utf8_unicode_ci NOT NULL default '',
value text collate utf8_unicode_ci NOT NULL,
UNIQUE KEY name (name)
)
I want to put the data of this table into array - to do that $config[name] = value;
For ex. If in database exists the entry name='email' and value='his@mail.com', then $config['email'] would be equal 'his@mail.com'.
How to do that? I think, need to use foreach function, but i don't know how.
<?php
$sql = "SELECT * FROM config";
$result = mysql_query($sql) OR exit;
$fetch = mysql_fetch_array($result);
$config = array();
foreach($fetch as $key => $value) {
$config[$key] = $value;
}
?>
What's wrong here?
Thank's.