0

I have some problems when I update my table with Ci Update. Here is my Code

$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); 

Problem is database name. Database name can possible include "." sign. eg( db3.9 )
So Ci is produce update query like this

UPDATE `db3`.`9`.`mytbl` SET `name` = 'myname' WHERE `id` = 1

So anyone can tell me how can i solve this CI update auto escape solution.
PS. removing database name from this query is not what i want.
because database,table and columns are dynamic.So i can't define globally what database,table and columns.

Samuel
  • 1
  • 2

2 Answers2

1

perhaps use ci's query function instead to avoid auto escaping

$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';");

i havent seen many examples of people using dots in their database names (even though it is technically allowed), but ive commonly seen underscores being used.

this might help Database, Table and Column Naming Conventions?

Community
  • 1
  • 1
James
  • 774
  • 6
  • 8
  • that's the right answer. Also, you could set 'protect_identifiers' to false in the DB config file, but that's global. As a hack, you can also set $db->_protect_identifiers to false. – user3632495 Aug 11 '14 at 07:20
  • yes . . . but it can't solve my problem. because my database name and columns is dynamic. I mean I don't know what database need to update and what columns are need to update.So i can't write query like this. – Samuel Aug 11 '14 at 07:43
  • @SeanPyae it should still work, since your executing a single update with each post request, ill update the answer to match your revised question – James Aug 11 '14 at 08:07
0

use the escape character in defining the dbname??? LIKE $db = "db3/.9"

Torrezzzz
  • 307
  • 2
  • 13