Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在CI_DB_active_记录类中传递参数$where to update函数内置代码点火器2.1_Php_Codeigniter_Query Builder - Fatal编程技术网

Php 如何在CI_DB_active_记录类中传递参数$where to update函数内置代码点火器2.1

Php 如何在CI_DB_active_记录类中传递参数$where to update函数内置代码点火器2.1,php,codeigniter,query-builder,Php,Codeigniter,Query Builder,我有一个记录,应该使用代码点火器2.1内置的更新功能进行更新。 因此,我不想单独定义close的位置,而是想像传递变量一样传递它 $this->db->update($table,$record,$where); (我知道这是内置的功能,但所有示例都以两步方式进行,使用where函数和update函数) 我应该创建一个单独的where函数并返回$where值以保持MVC模式清晰吗 function where($field,$value) 及 如何实现这一点?您可以通过以下任一方法实现: 方法

我有一个记录,应该使用代码点火器2.1内置的更新功能进行更新。 因此,我不想单独定义close的位置,而是想像传递变量一样传递它 $this->db->update($table,$record,$where); (我知道这是内置的功能,但所有示例都以两步方式进行,使用where函数和update函数)

我应该创建一个单独的where函数并返回$where值以保持MVC模式清晰吗

function where($field,$value)


如何实现这一点?

您可以通过以下任一方法实现:

方法1:您可以在第三个参数中将条件作为字符串传递

$this->db->update('mytable', $data, "id = $id");
$this->db->update('mytable', $data, array("id" => $id));
方法2:您可以在第三个参数中将条件作为数组传递

$this->db->update('mytable', $data, "id = $id");
$this->db->update('mytable', $data, array("id" => $id));
你在问题中提到的方法也是正确的

$this->db->where('id','3');
$this->db->update('data', $record);

您可以使用前面提到的两种方法来实现更多的面向对象。 然后,您将能够使用该函数更新任何表记录

而且上面的答案也是正确的

$this->db->update('mytable', $data, array("id" => $id));

我更喜欢流行款式对不起,伙计。它的oop风格。