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 |
MySql Connection | |
---|---|
Description | |
<?php require(“define.inc”); $conn=mysql_connect(HOSTNAME, DBUSER, DBPWD) or die(‘Could not connect: ‘ . mysql_error()); $task=”; switch($task){ ?> <?php |
PHP Sub String | |
---|---|
Description | |
<?php $rest = substr(“abcdef”, 0, -1); // returns “abcde” $rest = substr(“abcdef”, 2, -1); // returns “cde” $rest = substr(“abcdef”, 4, -4); // returns false $rest = substr(“abcdef”, -3, -1); // returns “de” $rest = substr(“abcdef”, -2); // returns “ef” $rest = substr(“abcdef”, -3, 1); // returns “d” ?> |
PHP Date Formate | |
---|---|
SL No | Description |
1 | if(function_exists(‘date_default_timezone_set’)) { date_default_timezone_set(‘Asia/Almaty’); } else{ putenv(“TZ=Asia/Almaty”); } |
2 | $transactionDateLocal=date(“Y-m-d H:i:s”,time()); |
3 | $transactionDateLocal=date(“Y-m-d g:i:s a”,time()); |
4 | <?php
$date = “2012-05-19 13:00”; echo $stamp = strtotime($date) . “<br />”; // outputs 1337432400 echo date(“Y-m-d g:i:s a”,strtotime($date)); // outputs 2012-05-19 1:00:00 pm ?> |
MySql Query | |
---|---|
SL No | Description |
1 | INSERT INTO table_name VALUES (value1, value2, value3); |
2 | UPDATE table_name SET column1=value, column2=value2 WHERE some_column=some_value |
3 | DELETE FROM table_name WHERE some_column = some_value |
SQL FOREIGN KEY | |
---|---|
SL No | Description |
1 |
ALTER TABLE t_orderitems ADD CONSTRAINT fk_UserId FOREIGN KEY (UserId) REFERENCES icat_users(id) |
Primary KEY with two fields | |
---|---|
SL No | Description |
1 |
ALTER TABLE sdp_product_mapADD CONSTRAINT ProductMap PRIMARY KEY (`SDPMapId`,`UpazilaCode`) |
Remove a File/Directory | |
---|---|
SL No | Description |
1 |
$filePath2=SITEDOCUMENT.'scode/assets/'.$LanguageId.'/svg/word_'.$GlyphId.'.svg'; if (file_exists($filePath2)){ unlink($filePath2); } |
2 |
rrmdir(SITEDOCUMENT.'scode/assets/'.$LanguageId); function rrmdir($dir) { foreach(glob($dir . '/*') as $file) { if(is_dir($file)) rrmdir($file); else unlink($file); } rmdir($dir); } |
© 2012-13 Md. Khurshed Alam Nayeem | |
---|---|
I’m not sure where you are getting your info, but great topic. I needs to spend some time learning more or understanding more.
Thanks for wonderful information I was looking for this info for my mission.
I’m not sure where you’re getting your info, but great topic. I needs to spend some time learning much more or understanding more.
Thanks for excellent information I was looking for this information for my mission.
I’m not sure where you’re getting your information, but great topic. I needs to spend some time learning much more or understanding more.
Thanks for fantastic info I was looking for this information for my mission.
I’ll immediately take hold of your rss as I can not find your e-mail subscription hyperlink or newsletter service.
Do you have any? Kindly allow me realize so that I may just subscribe.
Thanks.