Functions function delete($table, $conditions=”, $params=array()) The delete() method builds and executes a DELETE SQL statement.’$table’ is a table name of delete from.’$conditions’ and ‘$params’ is like where condition of delete statement Sample <?php $user=Yii::app()->db->createCommand() ->delete(‘tbl_user’, ‘user_id=:id’, array(‘:id’=>2)); ?> OUTPUT SQL DELETE FROM `tbl_user` WHERE user_id=:id
Category Archives: Yii Framework
Functions function insert($table, $columns) The insert() method builds and executes an INSERT SQL statement. Sample 1 <?php $user=Yii::app()->db->createCommand() ->insert(‘tbl_user’, array(‘username’=>’bsourcecode’,’usertype’=>1,’password’=>’hai’)); ?> OUTPUT SQL INSERT INTO `tbl_user` (`username`, `usertype`,’password’) VALUES (:username,:usertype, :password) Sample 2 <?php $name=’india’; $isactive=1; $command= Yii::app()->db->createCommand( “INSERT INTO regionmaster (`regionname`,`isactive`) VALUES (:name,:isactive)”); $command->bindValue(‘:name’, $name); $command->bindValue(‘:isactive’, $isactive); $sql_result = $command->execute(); ?> OUTPUT SQL INSERT […]
I posted here examples of createCommand Query with properties. createCommand Properties are distinct, from, group, having, join, limit, offset, params, pdoStatement, select and where. CDbCommand represents an SQL statement to execute against a database. bindParam used to bind a php variable to parameter in SQL query. bindValue is used to bind a value to and […]
Functions function update($table, $columns, $conditions=”, $params=array()) Sample The update() method builds and executes an UPDATE SQL statement. <?php $user=Yii::app()->db->createCommand() ->update(‘tbl_user’, array( ‘username’=>’bsourcecode’, ), ‘user_id=:id’, array(‘:id’=>1)); ?> OUTPUT SQL UPDATE `tbl_user` SET `username`=:username WHERE user_id=:id
beforeSave() beforeSave() class Mytable extends CActiveRecord { // Format 1 public function beforeSave() { if($this->isNewRecord) { $this->createddate=new CDbExpression(‘NOW()’); }else{ $this->modifieddate = new […]
This tutorial will help you to understand “how to handle password field in yii”. I used scenario concept to change password. So the rule of models was configured based on scenario concept of yii framework.It was working fine for me. In Model.php Rules public function rules() { return array( array(‘username, password,confirmpassword’, ‘required’, ‘on’=>’insert’), array(‘username, password,confirmpassword’, […]
This tutorial will help you to get the information about yii update function. I added the source code to update one or multiple records using different update function in yii framework model. <?php $model=User::model()->updateByPk($ID,array(“status”=>’DECLINED’)); $model=User::model()->updateAll(array( ‘first_name’=>”$firstname”, ’email’=>”$email” ), “UserID=$id and status IS NULL ” ); $model=User::model()->updateAll(array( ‘status’ => 1), ‘UserID =’.$userid); ?>
This tutorial will help you to delete the record from database table using model in yii framework. I added the code to delete one or more record using yii framework model. /** 1 **/ $model=User::model()->findByPk($id); if($model) $model->delete(); /** 2 **/ $model=User::model()->deleteAll(); /** 3 **/ $model=User::model()->deleteAll(array(“condition”=>”userid=’$id'”)); /** 4 **/ $mode=User::model()->deleteAll(“status=’A'”);
Create New Look For Pager Of Great Yii. Yii pagination widget is the one of the feature in yii framework. Listview and gridview have the pagination and it have the some basic properties, design and values for that properties. We can change the pager propertices and make new look for pagination. I added the sourcecode […]
Yii Admin Theme. You can view the demo and download this yii admin template. This Admin template name is “Adminblacktheme”. It is simple and useful one for admin section. I used two section in this template. They are create, manage section. Manage section cotains gridview table. DownloadDemo