How to Run Multiple Queries at Once in OOP
Note:The SQL Queries Shld be seperated by Semicolon(;)

$Conn = $this->dbConnect;
$strSQL = "SELECT name FROM tbSample1;";
$strSQL = $strSQL."SELECT age FROM tbSample1;";

if ($Conn->multi_query($strSQL)) 
{
	 do 
	 { 
		/* store first result set */
		if ($result = $Conn->store_result()) 
		{	
			while ($row = $result->fetch_row()) 
			{
				$item = array();
				$item = $row;
				$arrTempCounts[] = $item;
			}
			$result->free();
		}
		/* print divider */

		if ($Conn->more_results()) 
		{
		 print("-----------------n");
		}
	}while ($Conn->next_result());
}

Posted in PHP.

Storing Array In Cookie and Retrieving it

  $arrNames= array('Name'=>'Mugil',
               	   'Email'=>'Mugil@cse.com', 
	           'ContactNo'=>'9962945097');
  
  $strDetails = implode(',', $arrNames);

  setcookie('Details', $strDetails, time()+ 3600*24);

  if(isset($_COOKIE['Details']))
  {
    $arrDetails = explode(',', $_COOKIE['Details']);
	
    for($i=0;$i<count($arrDetails);$i++)
     print $arrDetails[$i]."
"; }
Posted in PHP.

Mysqli Method
Procedure

  DROP PROCEDURE IF EXISTS prSample1;
  CREATE PROCEDURE prSample1(OUT Name VARCHAR(255))
  BEGIN
    SET Name = 'Mugil';
    SELECT Name;
  END;

Call to Procedure From PHP

  $Conn = new mysqli('localhost', 'root', '', 'metroplots');				

  $strSQL = "CALL prSample1(@Name)";
  $stmt   = $Conn->prepare($strSQL);

  $stmt->execute();
  $stmt->bind_result($Name);	

  while($stmt->fetch())
   $strName = $Name;

Upper Case First Letter in  Word

{$city|capitalize}

Input

{assign var="name" value="mugil"}

Output

Mugil


How to Check for Variable in Array

 {if in_array($current_item,$selected_array}

How to Find Absolute Value

  {$launchDate|abs ne 0}

How to find substring in String

  {$launchDate|substr:0:4}

Using Foreach Loop

  {assign var="Count" value=1}
  {foreach from=$arrTestimonials item=foo}
   .
   .
   .
   .
   {assign var="Count" value=$Count+1}
   {/foreach}    

Creating Simple XML File In PHP

 <?php    
    header("Content-Type: text/plain");

    //create the xml document
    $xmlDoc = new DOMDocument();

    //create the root element
    $root = $xmlDoc->appendChild(
              $xmlDoc->createElement("Students"));

    //make the output pretty
    $xmlDoc->formatOutput = true;

    echo $xmlDoc->saveXML();
?>

Output

<?xml version="1.0"?>
<Students/>

Adding Nodes To XML Document

//create a tutorial element
  $tutTag = $root->appendChild(
              $xmlDoc->createElement("Student"));

  //create the author attribute
  $tutTag->appendChild(
    $xmlDoc->createAttribute("id"))->appendChild(
      $xmlDoc->createTextNode('105'));

  //create the title element
  $tutTag->appendChild(
    $xmlDoc->createElement("FirstName", 'Mugil'));

  //create the title element
  $tutTag->appendChild(
    $xmlDoc->createElement("LastName", 'Vannan'));

  //create the date element
  $tutTag->appendChild(
    $xmlDoc->createElement("Age", '24'));

Whole Code

 <?php    
    header("Content-Type: text/plain");

    //create the xml document
    $xmlDoc = new DOMDocument();

    //create the root element
    $root = $xmlDoc->appendChild(
              $xmlDoc->createElement("Students"));

    //create a tutorial element
  $tutTag = $root->appendChild(
              $xmlDoc->createElement("Student"));

  //create the author attribute
  $tutTag->appendChild(
    $xmlDoc->createAttribute("id"))->appendChild(
      $xmlDoc->createTextNode('105'));

  //create the title element
  $tutTag->appendChild(
    $xmlDoc->createElement("FirstName", 'Mugil'));

  //create the title element
  $tutTag->appendChild(
    $xmlDoc->createElement("LastName", 'Vannan'));

  //create the date element
  $tutTag->appendChild(
    $xmlDoc->createElement("Age", '24'));              

    //make the output pretty
    $xmlDoc->formatOutput = true;

    echo $xmlDoc->saveXML();
?>

Output

<?xml version="1.0"?>
<Students>
  <Student id="105">
    <FirstName>Mugil</FirstName>
    <LastName>Vannan</LastName>
    <Age>24</Age>
  </Student>
</Students>
    mysql_connect('localhost', 'root', '');
    mysql_select_db('sampleDB');
    
    $strSQL = 'SELECT * 
                 FROM tbAmenities 
                LIMIT 10';
                         
    $Result = mysql_query($strSQL); 

    $Response = array();
    $Posts    = array();
    
    while($row=mysql_fetch_array($Result)) 
    { 
        $id             =    $row['id']; 
        $amenityname    = $row['amenityname']; 
        
        $amenity[] = array('id'=> $id, 'amenity'=> $amenityname);    
    } 

    $Response['posts'] = $amenity;

    $fp = fopen('results.json', 'w');
    fwrite($fp, json_encode($Response));
    fclose($fp);