Drupal 7 : Select Query Format


Dynamic queries refer to queries that are built dynamically by Drupal rather than provided as an explicit query string. All Insert, Update, Delete, and Merge queries must be dynamic. Select queries may be either static or dynamic. Therefore, “dynamic query” generally refers to a dynamic Select query.

All dynamically built queries are constructed using a query object, requested from the appropriate connection object. As with static queries, in the vast majority of cases the procedural wrapper may be used to request the object. Subsequent directives to the query, however, take the form of methods invoked on the query object.


$result = db_select('table_name', 'table_alias')
    ->fields('table_alias') // just pass table_alias if you need select all the fields Or ->fields('table_alias',array('field_1', 'field_2', 'field_3', 'field_4', 'field_5'))
    ->condition('field_1', $field_1,'=')
    ->condition('field_2', $field_1,'=')
    ->execute()
    ->fetchAssoc();

this will work as good as we using simple select query as below;

$result = "SELECT * FROM table_name as alias WHERE field_1 = "'.$field_1.'" AND field_2 = "'.$field_2.'" ";


execute(): function will execute the query directly;

fetchAssoc(): function will fetch Associate array of records set directly;

Thanks.

Fatal error: Maximum execution time of 60 seconds exceeded in E:\server\xampp\htdocs\test\includes\common.inc


Fatal error: Maximum execution time of 60 seconds exceeded in E:\server\xampp\htdocs\test\includes\common.inc

When you are working on Drupal in your local host some times you get this type of error;
Fatal error: Maximum execution time of 30/60 seconds exceeded on your browser. I also got that issue and so after googling to many things i achieved to fix this, I added below code block in my settings.php.

1) open your settings.php (sites /default/settings.php)

2) add this code for PHP settings: line number between 147 – 180

ini_set(‘max_execution_time’, 0);

(you may get permission error, because by default setting.php is right protected. for that you can create a new setting.php file and make sure COPY AND PAST ALL data code in old setting.php then you can replace it )

This will fix your problem as per my knowledge.

Resize image function in joomla


// Here is the code for creating thumb image & re-size it.

currently you have call upload function in component like this,

if(!JFile::upload($fileTemp, $uploadPath))

now this function call replace with this line

if(!JFile::thumb($fileTemp, $uploadPath, 150, 100))

put this function after upload function at : libraries/joomla/filesystem/file.php


function thumb($file, $save, $width, $height)
	{
		@unlink($save);

		if (!$infos = @getimagesize($file)) {
			return false;
		}

		$iWidth = $infos[0];
		$iHeight = $infos[1];
		
		//$iRatioW = $width / $iWidth;
		//$iRatioH = $height / $iHeight;
		
		//$iNewH = $height;
		
		if(!empty($height))
			$iNewH = $height;
		
		if(!empty($width))
			$iNewW = $width;
	
		if(empty($height))
			$iNewH = ($iHeight/$iWidth)*$iNewW;
		
		///Condition if width blank then set autowidth... otherwise set passing width...
		if(empty($width))
			$iNewW = ($iWidth/$iHeight)*$iNewH;

		//Don't resize images which are smaller than thumbs
		if ($infos[0] < $width && $infos[1] < $height) {
			$iNewW = $infos[0];
			$iNewH = $infos[1];
		}

		if($infos[2] == 1) {

			$imgA = imagecreatefromgif($file);
			$imgB = imagecreate($iNewW,$iNewH);
			
          	if(function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
            	$transcolorindex = imagecolortransparent($imgA);
            		//transparent color exists
            		if($transcolorindex >= 0 ) {
             			$transcolor = imagecolorsforindex($imgA, $transcolorindex);
              			$transcolorindex = imagecolorallocate($imgB, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
              			imagefill($imgB, 0, 0, $transcolorindex);
              			imagecolortransparent($imgB, $transcolorindex);
              		//fill white
            		} else {
              			$whitecolorindex = @imagecolorallocate($imgB, 255, 255, 255);
              			imagefill($imgB, 0, 0, $whitecolorindex);
            		}
            //fill white
          	} else {
            	$whitecolorindex = imagecolorallocate($imgB, 255, 255, 255);
            	imagefill($imgB, 0, 0, $whitecolorindex);
          	}
          	imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
			imagegif($imgB, $save);        

		} elseif($infos[2] == 2) {

			$imgA = imagecreatefromjpeg($file);
			$imgB = imagecreatetruecolor($iNewW,$iNewH);
			imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
			imagejpeg($imgB, $save);
			

		} elseif($infos[2] == 3) {
			/*
			* Image is typ png
			*/
			$imgA = imagecreatefrompng($file);
			$imgB = imagecreatetruecolor($iNewW, $iNewH);
			imagealphablending($imgB, false);
			imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
			imagesavealpha($imgB, true);
			imagepng($imgB, $save);
			
		} else {
			return false;
		}
		return true;
	}

This function will helpful to you for re-sizing images in their proportions with good resolutions.