CodeIgniter Forums
How can I get active records NOT to add single quotes to int values? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How can I get active records NOT to add single quotes to int values? (/showthread.php?tid=58148)



How can I get active records NOT to add single quotes to int values? - El Forum - 05-20-2013

[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



How can I get active records NOT to add single quotes to int values? - El Forum - 05-21-2013

[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-guide/database/active_record.html

Also see the second answer here, using get_where
http://stackoverflow.com/questions/14548644/active-record-in-codeigniter-automatically-adds-quotes-around-where-clause-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!


How can I get active records NOT to add single quotes to int values? - El Forum - 05-21-2013

[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?



How can I get active records NOT to add single quotes to int values? - El Forum - 05-21-2013

[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



How can I get active records NOT to add single quotes to int values? - El Forum - 05-22-2013

[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