This tutorial will help you to upload the image with image extension validation, image size validation and image dimension validation. So we can fix the width and height for image.... Read More »
This tutorial will help you to upload the image with image extension validation, image size validation and image dimension validation. So we can fix the width and height for image.... Read More »
Scenarios validation is the one of the useful future in yii framwork and seperating the validation on any class derived from CModel. For example user registeration and updation will have different validation... Read More »
Yii have the multiple database connection by default. Yii components is used to make the relation between our models and database. To use the multiple database we have to configure the main.php file... Read More »
This tutorial will help you to find the result using DATE_FORMAT() function. ‘DATE_FORMAT’ function is used to convert the integer to date format value. I add the source code for this type of date search. In addCondition i used DATE_FORMAT function to filter the result. <?php public function search() { $criteria=new CDbCriteria; // condition for >= single date if(!empty($this->from_date) && empty($this->to_date)) { $this->from_date=date('Y-m-d',strtotime($this->from_date)); $criteria->addCondition( "DATE_FORMAT(checkin_time, '%Y-%m-%d') >= '$this->from_date'" ); } […]... Read More »
By default model classes are available within the 'protected/models' dirctory. Every class must be inherit from the CModel or subclass and we explained about yii 1.0 model structure... Read More »
CDbDataReader reads the rows from a result.CDbDataReader Query <?php $cdbdatareader = Yii::app()->db->createCommand() ->select('username, password') ->from('usermaster') ->query(); ?> columnCount & rowCount <?php echo $cdbdatareader->rowCount; echo $cdbdatareader->columnCount; ?> CDbDataReader Using read(), next() <?php $record=$cdbdatareader->read(); echo $record['username']; $cdbdatareader->next(); $record=$cdbdatareader->read(); echo $record['username']; ?> CDbDataReader Using foreach() & while()foreach()We can also retrieve the rows of data in CDbDataReader by using foreach. We can go forward only and cant take it backward. foreach($cdbdatareader as $records) { […]... Read More »
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 statementSample <?php $user=Yii::app()->db->createCommand() ->delete('tbl_user', 'user_id=:id', array(':id'=>2)); ?> Output DELETE FROM `tbl_user` WHERE user_id=:id... Read More »
Functions function update($table, $columns, $conditions='', $params=array()) SampleThe 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 UPDATE `tbl_user` SET `username`=:username WHERE user_id=:id... Read More »
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 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 INSERT INTO regionmaster (`regionname`,`isactive`) VALUES (:name,:isactive)... Read More »
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 SQL Parameter with automatic preparedFunctionstext, bindParam, executefrom, select, where, queryrowbindValuelimit, queryAlllimit, offset, orderDISTINCTandWhereorWheregroup, havingjoinPropertiesFunctions $connection=Yii::app()->db; […]... Read More »