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
CodeIgniter MySQL一次更新多个表db->;更新()数据库->;where()_Mysql_Codeigniter_Where Clause_Updating - Fatal编程技术网

CodeIgniter MySQL一次更新多个表db->;更新()数据库->;where()

CodeIgniter MySQL一次更新多个表db->;更新()数据库->;where(),mysql,codeigniter,where-clause,updating,Mysql,Codeigniter,Where Clause,Updating,我正在使用CodeIgniter,希望创建一个MySQL查询,更新多个表,如下所示: UPDATE TABLE1, TABLE2 SET TABLE1.NAME='Teddy', TABLE2.CLIENT_NOTES = 'Teddy is a good guy' WHERE VISITOR.ID = 1 如何使用CodeIgniter的db->update()和db->where()实现这一点? 这可能吗 谢谢你看这个。 注意。您需要使用$this->db->quer

我正在使用CodeIgniter,希望创建一个MySQL查询,更新多个表,如下所示:

UPDATE TABLE1, TABLE2
SET 
    TABLE1.NAME='Teddy', 
    TABLE2.CLIENT_NOTES = 'Teddy is a good guy' 
WHERE VISITOR.ID = 1
如何使用CodeIgniter的db->update()db->where()实现这一点? 这可能吗

谢谢你看这个。
注意。

您需要使用$this->db->query()来处理更复杂的问题


在转义、安全性等方面没有区别。Active Record只是将不同的字符串格式化为单个查询字符串。

您需要使用$this->db->query()来处理更复杂的问题


在转义、安全性等方面没有区别。活动记录只是将不同的字符串格式化为单个查询字符串。

首先,您需要为表指定别名,例如,
表1为t1
表2为t2
,因此,您的最终查询将变成这样

$this->db->set('t1.row','New value');
$this->db->set('t2.row','New value');
$this->db->where('t1.row','Your Condition');
$this->db->where('t2.row','Your Condition');
$this->db->update('table1 as t1, table2 as t2');

首先,您需要为表指定别名,例如,
table1作为t1
table2作为t2
,因此,您的最终查询将如下所示

$this->db->set('t1.row','New value');
$this->db->set('t2.row','New value');
$this->db->where('t1.row','Your Condition');
$this->db->where('t2.row','Your Condition');
$this->db->update('table1 as t1, table2 as t2');

我认为这是不可能的,我们需要一个接一个地更新。为什么不在复杂的查询中使用本机sql,更干净,更可读?你的意思是db->query(“这里的mysql代码”)?我正在努力确保我维护codeigniter的安全性和其他内置功能-我是不是正在通过使用“本机sql”来破坏这些功能或达到使用codeigniter的目的?我认为这是不可能的,我们需要一个一个地更新。为什么不在复杂的查询上使用本机sql,更干净、更可读?你是说db->query(“此处的mysql代码”)?我正在努力确保我维护codeigniter的安全性和其他内置功能-我是在通过使用“本机sql”来击败这些功能还是使用codeigniter的目的?我们是否确定绕过了安全性-我在阅读本页>>>“转义查询在将数据提交到数据库之前转义数据是一种非常好的安全做法。CodeIgniter有三种方法可以帮助您做到这一点:$this->db->escape()“是的,这很好。您需要确保使用查询绑定,您可以在该页面的底部了解这些绑定。这会自动转义,并(帮助)防止注入攻击$this->db->Query($sql,array(3,'live,'Rick'));”使用绑定的第二个好处是自动转义值,从而生成更安全的查询。您不必记住手动转义数据;引擎会自动为您执行此操作。“我们确定绕过了安全性吗?我感觉是这样的-在使用db->query()时-阅读此页面>>>“转义查询在将数据提交到数据库之前转义数据是一种非常好的安全做法。CodeIgniter有三种方法可以帮助您做到这一点:$this->db->escape()“是的,这很好。您需要确保使用查询绑定,您可以在该页面的底部了解这些绑定。这会自动转义,并(帮助)防止注入攻击$this->db->Query($sql,array(3,'live,'Rick'));”使用绑定的第二个好处是自动转义值,从而生成更安全的查询。您不必记住手动转义数据;当我使用这个代码时:$this->db->set('reg.email\u hash\u code','');$this->db->set('log.password','password');$this->db->where('reg.email\u hash\u code','hashcode');$this->db->where('log.emailid','email@gm.com“);$this->db->where('log.user\u id=reg.user\u id')$this->db->update('jc_登录为log,jc_注册为reg');我得到了以下错误:表'databasename.jc_登录为log,jc_注册'在我使用此代码时不存在:$this->db->set('reg.email_hash_code','');$this->db->set('log.password,password');$this->db->where('reg.email\u hash\u code','hashcode');$this->db->where('log.emailid','email@gm.com“);$this->db->where('log.user_id=reg.user_id');$this->db->update('jc_登录为log,jc_注册为reg');我得到以下错误:表'databasename.jc_登录为log,jc_注册为reg')不存在