duanmei1850 2016-06-10 08:04
浏览 35
已采纳

将POST存储在新变量中或使用$ _POST

Usually I call the POST method directly $_POST but if I assign the $_POST variable in new variable will the process speed faster? for example

method 1

/* $this->input->post('name') */
$this->db->where("name=".$this->input->post('name'));
$this->db->update(table, $this->input->post('name'));
$this->session->userdata(array("formdata", $this->input->post()));

method 2

$name = $this->input->post('name');
$this->db->where("name=".$name);
$this->db->update(table, $name);
$this->session->userdata(array("formdata", $this->input->post()));

Which method process faster?

Note: Sorry I don't understand how the process work in depth. I've around 30 input. Above query is just an example. There are multiple filter and processing section before sql insert/update. From what I know $_POST is a function and it take more resource than variable/array. I think using variable or array make the processing speed faster.a

  • 写回答

1条回答 默认 最新

  • douxiawei9318 2016-06-10 08:23
    关注

    The most efficient and better way is

    Generates an update string and runs the query based on the data you supply. You can pass an array or an object to the function. Here is an example using an array:

    $data = array(
            'title' => $this->input->post('title'),
            'name' => $this->input->post('name'),
            'date' => $this->input->post('date'),
          // ....... and soo ON.........
    );
    
    $this->db->where('id', $this->input->post('title'));
    $this->db->update('mytable', $data);
    

    Read updating-data

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等