2016-11-24 3 views
2

이것은 내 URL 링크이며 장치가 브라우저 본문에서 해당 값을 반환합니다. 이제이 데이터를 데이터베이스 테이블 이름 "IpRelay"에 삽입합니다. 먼저 장치 리턴 데이터를 폭발시킵니다. 그런 다음 분해 된 데이터를 삽입하려고합니다.URL에서 데이터베이스에 데이터를 삽입하는 방법

여기 내 코드입니다. 그러나 그것은 효과가 없습니다.

public function get_data(){ 

    $contents = file_get_contents('http://10.5.40.83'); 

    function multiexplode ($delimiters,$string) { 
     $ready = str_replace($delimiters, $delimiters[0], $string); 
     $launch = explode($delimiters[0], $ready); 
     return $launch; 
    } 

    $get_device_data = multiexplode(array(",",":",), $contents); 



    $this->IpRelay->create(); 
    $this->IpRelay->set($this->request->data['get_device_data']); 
    $save = $this->IpRelay->save(); 
    echo $save ? "I've created the link" : "Error creating link!"; 
    die($this->IpRelay->id); 
} 

저는 케이크가 새롭고 케이크 버전 2.7.5를 사용하고 있습니다. 제발 도와주십시오. 미리 감사드립니다

대신 위의 코드의
[ 

url=> http://10.5.40.83/ 

device return value=> 10,5,40,83:0,11,0,0,556 

][1] 

답변

1
$this->IpRelay->create(); 
$this->IpRelay->set($this->request->data['get_device_data']); 
$save = $this->IpRelay->save(); 
echo $save ? "I've created the link" : "Error creating link!"; 
die($this->IpRelay->id); 

이 코드 아래 사용하고 그것이

$this->IpRelay->read(null, 1); 
$this->IpRelay->set(array(
    'a'  => $get_device_data[0], 
    'b'  => $get_device_data[1], 
    'c'  => $get_device_data[2], 
    'd'  => $get_device_data[3], 
    'e'  => $get_device_data[4], 
    'f'  => $get_device_data[5], 
    'g'  => $get_device_data[6], 
    'h'  => $get_device_data[7], 
    'volt' => $get_device_data[8] 
)); 
$this->IpRelay->save(); 
1

은 당신의

$this->Model_name->read(null, 1); 
$this->Model_name->set(
    array(
     'field_1'  => $get_device_data[0], 
     'field_2'  => $get_device_data[1] 
    ) 
); 

$this->Model_name->save(); 
에 대한 쉽고 도움이 될 것입니다 희망 제대로 작동
관련 문제