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 Codeigniter更新动态数据库名称错误_Php_Codeigniter_Escaping_Sql Update - Fatal编程技术网

Php Codeigniter更新动态数据库名称错误

Php Codeigniter更新动态数据库名称错误,php,codeigniter,escaping,sql-update,Php,Codeigniter,Escaping,Sql Update,使用Ci update更新表时出现了一些问题。 这是我的密码 $db = $this->input->post('db'); $tbl = $this->input->post('tbl'); $name = $this->input->post('name'); $col = $this->input->post('col_name'); $id = $this->input->post('id

使用Ci update更新表时出现了一些问题。 这是我的密码

$db = $this->input->post('db');        
$tbl = $this->input->post('tbl');       
$name = $this->input->post('name');
$col = $this->input->post('col_name');    
$id =  $this->input->post('id');   
$array = array($col => $name);   
$this->db->where('id',$id);  
$this->db->update("`$db`.`$tbl`", $array); 
问题是数据库名。数据库名称可能包含“.”符号。eg(db3.9)
所以Ci是这样生成更新查询的

UPDATE `db3`.`9`.`mytbl` SET `name` = 'myname' WHERE `id` = 1
因此,任何人都可以告诉我如何解决此CI更新自动转义解决方案。
另外,从这个查询中删除数据库名称不是我想要的。

因为数据库、表和列是动态的。所以我不能全局定义什么数据库、表和列。

在定义数据库名时使用转义字符???像
$db=“db3/.9”

可能使用ci的查询功能来避免自动转义

$db = $this->input->post('db');        
$tbl = $this->input->post('tbl');       
$name = $this->input->post('name');
$col = $this->input->post('col_name');    
$id =  $this->input->post('id');
$this->db->query("UPDATE `$db`.`$tbl` SET `$col` = '$name' WHERE `id` = '$id';");
我还没有看到很多人在数据库名称中使用点的例子(尽管技术上允许),但我经常看到使用下划线


这可能会有所帮助,这是正确的答案。此外,您可以在DB配置文件中将“protect_identifiers”设置为false,但这是全局的。作为黑客,您还可以将$db->\u protect\u标识符设置为false.yes。但它不能解决我的问题。因为我的数据库名称和列是动态的。我的意思是我不知道哪些数据库需要更新,哪些列需要更新。所以我不能像这样编写查询。@SeanPyae它应该仍然可以工作,因为您对每个post请求执行一次更新,我会更新答案以匹配您修改过的问题