从phpmyadmin插入导出的php数组

lvmkulzt  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(439)

我已经在php-my-admin中从mysql数据库导出了数据。我将其导出为php数组。

$measurements = array(
  array('measurement_id' => '1','measurement_name' => 'bag','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '2','measurement_name' => 'bowl','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '3','measurement_name' => 'box','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '4','measurement_name' => 'handful','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '5','measurement_name' => 'package','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '6','measurement_name' => 'piece','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '7','measurement_name' => 'pizza','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '8','measurement_name' => 'slice','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '9','measurement_name' => 'spoon','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '10','measurement_name' => 'teaspoon','measurement_last_updated' => '2018-01-03 14:40:49'),
  array('measurement_id' => '11','measurement_name' => 'tablespoon','measurement_last_updated' => '2018-01-03 14:40:49')
);

如何将其再次插入数据库?
这就是我尝试过的:

$array_size = sizeof($measurements);
for($x=0;$x<$array_size;$x++){
            $temp = $measurements[$x];
            print_r($temp);
}
gwo2fgha

gwo2fgha1#

如果你开始使用这种结构,我会做如下事情:

foreach($measurements as $v){
  functionForInsertingRows($v)
}

然后在另一个函数中:

functionForInsertingRows($aInc){
  update tableName set 
  measurement_name = $aInc["measurement_name"],
  measurement_last_updated = $aInc["measurement_last_updated"]
  where measurement_id = $aInc["measurement_id"]
}

注意:这是psuedo代码,但这是我将使用的想法。insert或update函数将使用任何您想要的技术来更改数据库。

相关问题