PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 9, 2022

[FIXED] How to use where clause on the yii?

 January 09, 2022     yii     No comments   

Issue

I need to use where clause on yii, below of my code, I need to add where activated == 0 && send_email == 0.

$model = User::model()->findAll();

Thanks


Solution

There are multiple ways to do this:

$model = User::model()->findAll('activated=0 AND send_email=0');

Or,

$model = User::model()->findAll('activated=:activated And send_email=:sendEmail',
                                   array(':activated'=>0,':sendEmail'=> 0));

Or,

$criteria = new CDbCriteria;     
$criteria->condition='activated=:activated AND send_email=:sendEmail';
$criteria->params=array(':activated'=>0,':sendEmail'=>0);
$model=User::model()->findAll($criteria);

Or,

$model = User::model()->findAllByAttributes(array('activated'=>0, 'send_email'=>0));

Or,

$model = User::model()->findAllBySql('SELECT * FROM user WHERE activated=:activated AND send_email=:sendEmail', array(':activated'=>0, 'sendEmail'=>0));

More info here. Hope that helps :)



Answered By - Criesto
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing