3v4l.org

run code in 300+ PHP versions simultaneously
<?php define("STATE_ID","3"); define("DATA_CACHE_TIMEOUT","9999"); class ImportController extends Controller { public function actionIndex() { $t1=date("r"); $ts1=microtime(true); $tot=0; echo "\r\n<p> ******** Started at $t1 ******** </p>\r\n"; $connection = Yii::app()->db; $command = $connection->createCommand('SELECT * FROM seccsirsa LIMIT 0,10'); $rows = $command->queryAll(); //executes the SQL statement and returns the first row of the //$res = array(); foreach ($rows as $row) { extract($row); echo "\r\n<p>Full Name: $Name_en ($Name_h) </p>\r\n"; //echo "<br /> ".$this->getDistId($District."DEL"); echo "<br /> ".$this->getDistId($District); } $t2=date("r"); $ts2=microtime(true); $diff=($ts2-$ts1); echo "\r\n<p> ******** Stopped at $t2 ******** </p>\r\n"; echo "\r\n<p> ******** Total Execution Time: $diff microseconds ******** </p>\r\n"; echo "\r\n<p> ******** Total Records Imported: $tot ******** </p>\r\n"; } private function getDistId($District){ //Select if record exists $District=trim(strtolower($District)); $connection = Yii::app()->db; $connection->active=true; $command = $connection->createCommand("SELECT LR_ID FROM tblLandRegion WHERE lower(LR_Name) = '$District' AND LR_Type='District' "); $row = $command->queryRow(); //If no record found if($row===false){ //Insert record in DB (Master Table) $command = $connection->createCommand("INSERT INTO tblLandRegion (LR_Name,LR_Type) VALUES('$District', 'District') "); $rowCount=$command->execute(); if($rowCount==0){ die("FATAL ERROR 0x01: Failed to insert $District in Master table :: ".__FILE__." at line nunber ".__LINE__); } else{ //Cache and Return the PK/ID of the new inserted record. $row = Yii::app()->cache->get('cache_'.$District."_".STATE_ID); if (($row === false) || row($res)) { $District=trim(strtolower($District)); $connection = Yii::app()->db; $command = $connection->createCommand("SELECT LR_ID FROM tblLandRegion WHERE lower(LR_Name) = '$District' AND LR_Type='District' ORDER BY LR_ID DESC"); $row = $command->queryRow(); Yii::app()->cache->set('cache_'.$District."_".STATE_ID, $row, DATA_CACHE_TIMEOUT); } $District_ID=$row['LR_ID']; //Insert record in DB (Reference Table) $command = $connection->createCommand("INSERT INTO tblDistrict (District_ID, State_ID) VALUES('$District_ID', '".STATE_ID."') "); $rowCount=$command->execute(); if($rowCount==0){ die("FATAL ERROR 0x02: Failed to insert $District in Reference table :: ".__FILE__." at line nunber ".__LINE__); } return $District_ID; } } else{ //Return the PK/ID of the record. return $row['LR_ID']; } } } ?>

preferences:
32.62 ms | 402 KiB | 5 Q