我需要将数组数据插入 MySQL DB。下面提供了我的代码。问题是query
等于
插入
MyTab
(数组)值(数组,数组,数组,数组,数组,数组,数组,数组,数组,数组,数组)
那么,为什么我得到Array
而不是数组值?
$columns = array();
$values = array();
$columns[] = array('Num','appearanceTime');
$curr_time = new DateTime();
while($row=mysql_fetch_assoc($result_arr)) {
$values[] = array($row['Num_arr'],$curr_time);
}
$cols = implode(",",$columns);
$vals = implode(",",$values);
$query = "INSERT INTO `MyTab` ($cols) VALUES ($vals)";
更新此代码在行返回内部服务器错误$vals = implode(...)
。
$columns = array('Num','appearanceTime','earliestTime'); $values = 数组();
$curr_time = new DateTime();
while($row=mysql_fetch_assoc($result_arr)) {
$values[] = array($row['Num_arr'],$curr_time,$row['ETA']);
}
$cols = implode(",",$columns);
function get_values($arr) {
return '(' . implode(',', $arr) . ')';
}
$vals = implode(',', array_map('get_values', $values));
$query_queue = "INSERT INTO `MyTab` ('" . $cols . "') VALUES ('" . $vals . "')";