Memcached Working with PHP | |
---|---|
Description | |
<?php/*=======connect Memcache===============*/ $m = new Memcache; $m->connect('localhost', 11211) or die ("Could not connect"); $expires = 60*60*24*30; // seconds, minutes, hours, days $data[] = (object) array('UnitId'=>'1', 'UnitName'=>'pic'); $data[] = (object) array('UnitId'=>'2', 'UnitName'=>'bundle'); $arr['rows']=$data; $str=json_encode($arr); /*=======Memcache Object Ready=========*/ //echo $str; $obj = new stdClass; $obj->str = $str; /*=======Set Memcache Obj==============*/ $m->set('key', $obj, false, $expires ); /*=======Delete Memcache Obj===========*/ //$m->delete('key'); /*=======Fetch Memcache Obj============*/ $get_result = $m->get('key'); /*=======Print Memcache JSON obj=======*/ echo $get_result->str; ?> |
List of all Column in a MySql Table | |
---|---|
Description | |
<?php$host_name='localhost'; $db_name="dgfplmis_db"; $UserID="root"; $Password=""; $connection=mysql_connect($host_name,$UserID,$Password) or die("Could not connect to server"); $db=mysql_select_db($db_name,$connection) or die("Could not select database"); $sql="SHOW COLUMNS FROM `2012_f7_tab` "; $result=mysql_query($sql,$connection); while($row=mysql_fetch_assoc($result)){ $arr[]=$row['Field']; //print_r($row); } echo json_encode($arr); ?> |
List of All Files in a Directory | |
---|---|
Description | |
<?php//path to directory to scan $directory = "images/project1/620x378/"; //get all image files with a .jpg extension. $images = glob($directory . "*.jpg"); //print each file name foreach($images as $image) { echo $image; } ?> |
XML Generation | |
---|---|
Description | |
<?php header(“Content-type: text/xml”); echo $str; ?> |
PHP E-mail Sending | |
---|---|
Description | |
<?php $to .= ‘ [email protected] ‘; // subject // message <body> <p>Here are the birthdays upcoming in August!</p> <table> <tr> <th>Person</th><th>Day</th><th>Month</th><th>Year</th> </tr> <tr> <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> </tr> </table> </body> </html> ‘; // To send HTML mail, the Content-type header must be set // Additional headers // Mail it |