Tuesday, March 29, 2011

When to use InnoDB?


InnoDB uses row level locking, has commit, rollback, and crash-recovery capabilities to protect user data. It supports transaction and fault tolerance.


When to use MyISAM?


MyISAM is designed with the idea that your database is queried far more than its updated and as a result it performs very fast read operations. If your read to write(insert|update) ratio is less than 15% its better to use MyISAM.

MyISAM Or InnoDB MySQL engine?


MyISAM limitations

No Foriegn keys and cascading deletes and updates
No rollback abilities
No transactional integrity (ACID compliance)
Row limit of 4,284,867,296 rows
Maximum of 64 indexes per row


InnoDB Limitations

No full text indexing
Cannot be compressed for fast, read-only

Monday, March 28, 2011

Generate Random 10 digit String


function genRandomString($length) {
    //$length = 10;
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = '';  
    for ($p = 0; $p < $length; $p++)
{
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}

   echo strtoupper(genRandomString(10));

Generates a random string of variable length


function getUniqueCode($length = "")

  {

   $code = md5(uniqid(rand(), true));

   if ($length != "") return substr($code, 0, $length);

   else return $code;

  }

Thursday, March 24, 2011

Google Refferal Code


function search_engine_query_string($url = false)
{
    if(!$url && !$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false) {
        return '';
    }
    $parts_url = parse_url($url);
    $query = isset($parts_url['query']) ? $parts_url['query'] : (isset($parts_url['fragment']) ? $parts_url['fragment'] : '');
    if(!$query) {
        return '';
    }
    parse_str($query, $parts_query);
    $res = isset($parts_query['q']) ? $parts_query['q'] : (isset($parts_query['p']) ? $parts_query['p'] : '');
  if($res)
{
preg_match("/[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))/", $res, $matches);
return $matches[0];
}
return false;
}

Read a page's GET URL variables and return them as an associative array.


function getUrlVars()
 {
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

  for(var i = 0; i < hashes.length; i++)
  {
   hash = hashes[i].split('=');
   vars.push(hash[0]);
   vars[hash[0]] = hash[1];
  }

  return vars;
 }


Make Tab Dynamically Active Using JQuery and PHP

   // Some condition According to this assign valoues of $tab_act as 0, 1, 2
  // First Condition
  if(!empty($_GET)){
    $tab_act = 1;
  }else{
     $tab_act = 0;
  }
// Second Condition if Values are come through url make it an array
$name = explode('/',$_SERVER['REQUEST_URI']);
$name_url = $name['1'];
if($name_url == ''){
   $tab_act = 0;
} else{
   $tab_act = 1;
}
// Note :- Use Condition According to your requirement and assign values in $tab_act = 0;
?>

$(document).ready(function() {

//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:eq()").addClass("active").show(); //Activate first tab
$(".tab_content:eq()").show(); //Show first tab content

//On Click Event
$("ul.tabs li").click(function() {

$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});

Wednesday, March 23, 2011

Extract Email Address From Search URL ( Different Search Engine )in PHP

function search_engine_query_string($url = false) {

if(!$url) {
$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
}
if($url == false) {
return '';
}

$parts = parse_url($url);
parse_str($parts['query'], $query);

$search_engines = array(
'bing' => 'q',
'google' => 'q',
'yahoo' => 'p'
);

preg_match('/(' . implode('|', array_keys($search_engines)) . ')\./', $parts['host'], $matches);

return isset($matches[1]) && isset($query[$search_engines[$matches[1]]]) ? $query[$search_engines[$matches[1]]] : '';

}
?>

$url = "http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=test+hanzala+test%40test.com+worpres&aq=f&aqi=&aql=&oq=";

$url_bing = "http://www.bing.com/search?q=Hanzala+Subhani+h.subhani%40live.com&go=&form=QBRE&filt=all&qs=n&sk=";

$url_yahoo = "http://in.search.yahoo.com/search;_ylt=A8pWB9pHxYlNdhMAUvy7HAx.;_ylc=X1MDMjExNDcyMzAwMwRfcgMyBGFvAzEEZnIDeWZwLXQtNzA0BGhvc3RwdmlkA0JDSzd6M2xsbWs4RkpXc0tUWHRhMVFjSmVEaXhCMDJKeFVjQUFGMlAEbl9ncHMDMARuX3ZwcwMxNgRvcmlnaW4Dc3JwBHF1ZXJ5A2hhbnphbGEgaC5zdWJoYW5pQGxpdmUuY29tBHNhbwMxBHZ0ZXN0aWQDU01FSU4wMQ--?p=hanzala+h.subhani%40live.com&fr2=sb-top&fr=yfp-t-704&rd=r1";
//$url = "http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=test+hanzala+worpres&aq=f&aqi=&aql=&oq=";
$search_url="";
echo "Res=".$search_url = search_engine_query_string($url_yahoo);
echo "
";


   preg_match("/[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))/", $search_url, $matches);
  echo $matches[0];
?>

Function for Extract Search String From Search URL ( Different Search Engine )in PHP

function search_engine_query_string($url = false) {

if(!$url) {
$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false;
}
if($url == false) {
return '';
}

$parts = parse_url($url);
parse_str($parts['query'], $query);

$search_engines = array(
'bing' => 'q',
'google' => 'q',
'yahoo' => 'p'
);

preg_match('/(' . implode('|', array_keys($search_engines)) . ')\./', $parts['host'], $matches);

return isset($matches[1]) && isset($query[$search_engines[$matches[1]]]) ? $query[$search_engines[$matches[1]]] : '';

}

Monday, March 21, 2011

Show All monthly Archive in Wordpress

Please follow the step

write the following code just above
while ( have_posts() ) : the_post();
loop

$name = explode('/',$_SERVER['REQUEST_URI']);
$year = $name[1];
$month = $name[2];
$args = array(
'posts_per_page' => -1,
'year' => $year,
'monthnum' => $month,
'order' => 'ASC'
);
query_posts( $args );



Function Used to get splitted URL
$name = explode('/',$_SERVER['REQUEST_URI']);

Monday, March 7, 2011