Php 如何从url向数据库中插入数据
这是我的url链接和设备在浏览器正文中返回的对应值。现在,我将此数据插入数据库表名Php 如何从url向数据库中插入数据,php,mysql,cakephp,Php,Mysql,Cakephp,这是我的url链接和设备在浏览器正文中返回的对应值。现在,我将此数据插入数据库表名IpRelay。首先,我爆炸我的设备返回数据。然后我尝试插入分解数据 这是我的密码。但它不起作用 public function get_data(){ $contents = file_get_contents('http://10.5.40.83'); function multiexplode ($delimiters,$string) { $ready = str_repla
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->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();
希望这对你的工作更容易和有帮助
$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();
$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();