2010-11-27 198 views
0
<?PHP 

// primarily a method for storing data 
// arrays are counted from 0 

$hosts = array(
array("ronmexico.kainalopallo.com/","beforename=$F_firstname%20$F_lastname&gender=$F_gender","Your Ron Mexico Name is ","/the ultimate disguise, is ([^<]+)<\/b><\/u>/s"),<u><b>([^<]+)<\/b><\/u>/s"), 

array("rumandmonkey.com/widgets/toys/mormon/index.php","gender=$F_gender&firstname=$F_firstname&surname=$F_lastname","Your Mormon Name is ","/ 
My <p>My Mormon name is 
<b>([^<]+)<\/b>!<br \/>/s") 
); 

return $hosts; 

?> 

如何将此数组存储到mysql数据库中。如何将php数组数据存储到mysql数据库中

+0

你应该从这里学习基础开始:http://www.w3schools.com/php/php_mysql_intro.asp – 2010-11-27 11:00:39

回答

1

只是遍历数组,每一个元素插入到表

foreach($hosts as $key => $value){ 
    mysql_query('INSERT INTO table (field) VALUES ("'.$value.'")'); 
} 
1

您可以使用PHP serialize功能来存储数组和对象在MySQL

+0

+1回答但OP应该避免将数组/对象存储在数据库中! – AlexV 2010-11-29 16:47:40

1

您可以使用json_encode存放时:

$fruit_color = array("apple" => "red", "banana" => "yellow", "cherry" => "red"); 
$encoded = json_encode($fruit_color); //Turn your array into json-readable string 

和从数据库中检索时的json_decode:

$result = mysql_fetch_assoc($sql); 
$decoded = json_decode($result[column_name]); 
相关问题