php - 如何从 url 将数据插入数据库

标签 php mysql cakephp

这是我的 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

enter image description here

最佳答案

希望它对您更轻松且有帮助

$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/

相关文章:

php - 计算行数,直到达到值

php - 使用 PHP 和 MySQL 查询的网站过滤器

java - Apache ANT Exec - 处理 exec/CakePHP 控制台提示

php - 数据库错误 Cakephp

php - CakePHP:使用 optgroups 在选择上设置默认值

php - 使用phpexcel将excel公式转至mysql数据库

php - 我希望当我发送消息时出现警报

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

php - 用于创建管理面板的 Yii 扩展

mysql - 使用 INNER JOIN 重写 UPDATE 查询而不使用 IN