这是我的 url 链接和设备在浏览器正文中返回相应的值。现在,我将此数据插入到名为 IpRelay
的数据库表中。首先我爆炸我的设备返回数据。然后我尝试插入分解数据。
这是我的代码。但它不起作用。
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);
}
我是 cakephp 新手,我使用 cake 版本 2.7.5。 请你帮我一下。
url=> http://10.5.40.83/
device return value=> 10,5,40,83:0,11,0,0,556
最佳答案
希望它对您更轻松且有帮助
$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();
关于php - 如何从 url 将数据插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40783394/