2016-11-24 2 views
2

Dies ist meine URL Link und Gerät geben entsprechenden Wert im Browser body. Jetzt füge ich diese Daten in meinen Datenbanktabellennamen "IpRelay" ein. Zuerst explodiere ich meine Geräte-Return-Daten. Dann versuche ich, explodierte Daten einzufügen.Wie füge ich Daten in die Datenbank von URL

Hier ist mein Code. Aber es funktioniert nicht.

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

Ich bin neu in Kuchen und ich benutze Kuchen Version 2.7.5. Würdest du mir bitte helfen. Vielen Dank im Voraus

[ 

url=> http://10.5.40.83/ 

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

][1] 

Antwort

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

Statt oben Code, den ich unter diesem Code verwenden und es funktioniert

$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

Hoffen, dass es einfacher und hilfreich für Ihre

$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(); 
Verwandte Themen