Welcome Guest, Not a member yet? Register   Sign In
How can I get active records NOT to add single quotes to int values?
#1

[eluser]behnampmdg3[/eluser]
Code:
$this->db->select('products_table.id, code, class, category, status, price, production_date, products_status.title AS STATUS');
$this->db->from('products_table');
$this->db->join('products_status', 'products_status.id = products_table.status');
//$this->db->order_by('products_table.id');
$this->db->where('products_table.id >', $record_start);
$this->db->where($data);
$this->db->limit(10);
$query = $this->db->get();
The code above creates the query below. The type of the column class is INT but it adds the single quotes and I don't want single quotes for type INT in MySql. How can I stop active records to add single quotes to int columns?

Thanks


Code:
SELECT `products_table`.`id`,
       `code`,
       `class`,
       `category`,
       `status`,
       `price`,
       `production_date`,
       `products_status`.`title` AS STATUS
FROM   products_table
       JOIN `products_status`
         ON `products_status`.`id` = `products_table`.`status`
WHERE  `products_table`.`id` > 0
       AND `class` = '2'
LIMIT  10
#2

[eluser]boltsabre[/eluser]
Try sending it with the third WHERE paramter FALSE to disable automatic escaping by active records. Search the page below for:
$this->db->where();
to see the documentation
http://ellislab.com/codeigniter/user-gui...ecord.html

Also see the second answer here, using get_where
http://stackoverflow.com/questions/14548...ause-value

Something like:
Code:
$this->db->where('class', $data, FALSE);

Let us know how it goes, and mark this post as answered if it works. Thanks!
#3

[eluser]behnampmdg3[/eluser]
Thanks I realise this Smile but as you can see I am sending an array of mixed data and I was hoping that CI can differentiate between int and other type.

$this->db->where($data);

Does it make sense?
#4

[eluser]phpLearner[/eluser]
Where did you write the array data?

and write the where query directly instead of passing array

you can also try writing query directly

$sql="SELECT * FROM table WHERE id > ? AND class=? ";
$query=$this->db->query($sql,array($id,$class));

check if this works
#5

[eluser]boltsabre[/eluser]
Well can't you just split your $data array then, something like:
Code:
$this->db->where( $data[0], $data[1], FALSE);  // numeric array

// or
$this->db->where( $data['column_name'], $data['column_value'], FALSE);  // associative array




Theme © iAndrew 2016 - Forum software by © MyBB