I need to insert array data into MySQL DB. My code is provided below. The problem is that query
is equal to
INSERT INTO
MyTab
(Array) VALUES (Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array)
So, why do I get Array
instead of array values?
$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)";
UPDATE
This code returns Internal Server Error at the line $vals = implode(...)
.
$columns = array('Num','appearanceTime','earliestTime'); $values = array();
$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 . "')";