2016-11-24 14 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を使用しています。 お願いします。 Thanksにおけるadvance

[ 

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); 

Insteadのabove code I am using belowこのcode及びit works properly

$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

Hope it IS easierおよびhelpfulためyour

$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(); 
関連する問題