Files
cm-app-crawlspider/homestead/application/models/PlaceModel.php

37 lines
966 B
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class PlaceModel extends MY_Model
{
private $table = 'cm_naver_place';
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function save($places)
{
$inserted = array();
foreach($places[0]->data->places->items as $place) {
if($this->db->where('NId', $place->id)->from($this->table)->count_all_results() == 0) {
if($this->db->insert($this->table, array(
'NId' => $place->id,
'Category' => $place->category,
'Name' => $place->name,
'RoadAddress' => $place->roadAddress,
'Address' => $place->address,
'CommonAddress' => $place->commonAddress,
'Phone' => $place->phone,
'X' => $place->x,
'Y' => $place->y,
'CreatedAt' => date('Y-m-d H:i:s'),
)))
array_push($inserted, $this->db->insert_id());
}
}
return ['inserted' => $inserted];
}
}