多维数组入库问题
print_r($dbinsert)显示内容:
Array
(
[0] => Array
(
[apmac] => 0q:4e:cb:00:01:09
[pub_ip] => 11.24.24.7
[priv_ip] => 12.18.1.3
[hwver] => VA500
[fwver] => 69.0.0
[vsmip] => 12.25.1.19
[conntime] => 677822
[boottime] => 49950
[state] =>
[statetime] => 2013-7-12 18:34:5
[hostname] => name1
[location] => 0004.003.01
[admin_id] => 0
)
[1] => Array
(
[apmac] => 10:qe:cv:02:00:37
[pub_ip] => 11.24.24.7
[priv_ip] => 12.18.1.3
[hwver] => VA500
[fwver] => 69.0.0
[vsmip] => 12.25.1.19
[conntime] => 169547
[boottime] => 403315
[state] =>
[statetime] => 2013-7-12 18:34:5
[hostname] => nam2
[location] => 0004.003.01
[admin_id] => 0
)
[2] => Array
(
[apmac] => r0:ve:cb:00:ff:04
[pub_ip] => 13.24.28.7
[priv_ip] => 92.18.1.18
[hwver] => V
[fwver] => 6.)
[vsmip] => 12.25.1.79
[conntime] => 168
[boottime] => 144497
[state] =>
[statetime] => 2013-7-12 18:34:5
[hostname] => name5
[location] => 0004.003.01
[admin_id] => 0
)
)
问题:
我要把这些内容插入数据库表table3中,表结构跟返回的内容一样且顺序也一样
请问该如何写php程序呢?
[解决办法]
$f = '';
$v = array()
foreach($dbinsert as $row) {
if(empty($f)) $f = join(',', $array_key($row));
$v[] = "('" . join("','", $row) . "')";
}
$sql = "insert into table3 ($f) values " . join(',', $v);
//执行 $sql 的语句