CodeIgniter Forums
should I keep as is or possible to re-write using Active Record? - 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: should I keep as is or possible to re-write using Active Record? (/showthread.php?tid=45590)



should I keep as is or possible to re-write using Active Record? - El Forum - 09-27-2011

[eluser]Brad K Morse[/eluser]
I am refactoring most of my queries using Active Record, this is for an application that uses Oracle for a database.

Should I leave this query as is or is there an option for BETWEEN and what about using preg_replace within it?

I am guessing I could use something like:

Code:
->where('SP_COMMENTS.SP_COMMENTS_COMPLETION_DATE >, preg_replace('/(\d{6})(\d{2})/', '${1}01', date("Ymd", strtotime($this->input->post("user_begin_date"))))
->where('SP_COMMENTS.SP_COMMENTS_COMPLETION_DATE <, preg_replace('/(\d{6})(\d{2})/', '${1}01', date("Ymd", strtotime($this->input->post("user_end_date"))))

Code:
$q = $this->db->query("
SELECT distinct
  *
FROM
  SP_COMMENTS
WHERE
  SP_COMMENTS.SP_COMMENTS_USERNAME = '".$user."'
AND
  SP_COMMENTS.SP_COMMENTS_YEAR_CODE = '".$year_code."'
AND
  SP_COMMENTS.SP_COMMENTS_COMPLETION_DATE
BETWEEN ".preg_replace('/(\d{6})(\d{2})/', '${1}01', date("Ymd", strtotime($this->input->post("user_begin_date"))))."
AND ".date("Ymd", strtotime($this->input->post("user_end_date")))."
");