Yii2批量入库数据6e6f4c7840925e32ab7d3ee66b0db8f9
//快递信息入库 public function actionAddExpress(){ $url = 'http://v.apistore.cn/api/c95/table?key='; $data = json_decode(self::actionCurlRequest($url),true); $res = $data['result']; Yii::$app->db->createCommand()->batchInsert(Express::tableName(), ['com','name'], $res)->execute(); print_r($res); }
Yii::$app->db->createCommand()->batchInsert(Express::tableName(), ['com','name'], $res)->execute();
重点是这句话!
Express是model的名字
['com','name']是表里面的字段
$res是要入库的数组
通往牛逼的路上,在意的只有远方!