We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Active Record problem with SQL functions

Development and Programming

neilkb's avatar
neilkb
4 posts
12 years ago
neilkb's avatar neilkb

Hi, can anyone tell me how to convert this:

$query = $this->EE->db->query("SELECT entry_id, entry_date FROM exp_twitter WHERE entry_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL " . $this->tw_tweet_interval_limit . " " . $this->tw_tweet_interval . "))");

to something like this:

$this->EE->db->select('entry_id, entry_date');
$this->EE->db->where('entry_date <', 'UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL ' . $this->tw_tweet_interval_limit . ' ' . $this->tw_tweet_interval . ')))');
$query = $this->EE->db->get('exp_twitter');

at the moment the Active Record select is being skipped.

Thanks

       
neilkb's avatar
neilkb
4 posts
12 years ago
neilkb's avatar neilkb

Incase this is of use to anyone, here is the solution I found.

$this->EE->db->select('entry_id, pub_date');
$this->EE->db->where('pub_date <', 'UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL ' . $this->EE->db->escape_str($this->rss_feed_interval_limit) . ' ' . $this->EE->db->escape_str($this->rss_feed_interval) . '))', FALSE);
$query = $this->EE->db->get('exp_rss_feed_data');

Adding the FALSE parameter to WHERE stops Active Record from doing an automatic escape.

$this->db->where() accepts an optional third parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.