Monday, 30 April 2012

PHP Interview questions 19


76) What is the difference between char and varchar data types?
Ans :      Set char to occupy n bytes and it will take n bytes even if u r storing a value of n-m bytes
Set varchar to occupy n bytes and it will take only the required space and will not use the n bytes
eg. name char(15) will waste 10 bytes if we store 'romharshan', if each char takes a byte eg. name varchar(15) will just use 5 bytes if we store 'romharshan', if each char takes a byte. rest 10 bytes will be free.

77) What is the functionality of md5 function in PHP?
Ans :      Calculate the md5 hash of a string. The hash is a 32-character hexadecimal number. I use it to generate keys which I use to identify users etc. If I add random no techniques to it the md5 generated now will be totally different for the same string I am using.

78) How can I load data from a text file into a table?
Ans :      you can use LOAD DATA INFILE file_name; syntax to load data from a text file. but you have to make sure thata) data is delimited
b) columns and data matched correctly

79) How can we know the number of days between two given dates using MySQL?
Ans :      SELECT DATEDIFF("2007-03-07","2005-01-01");
                 
80) How can we know the number of days between two given dates using PHP?
Ans :      $date1 = date("Y-m-d");
$date2 = "2006-08-15";
$days = (strtotime($date1) - strtotime($date2)) / (60 * 60 * 24);

No comments:

Post a Comment