Php Interview Questions and Answers for Experienced

1) How can we know the number of days between two given dates using PHP?
A) Simple arithmetic:
$date1 = date(‘Y-m-d’);
$date2 = ‘2006-07-01’;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo “Number of days since ‘2006-07-01’: $days”;
2) How can we repair a MySQL table?
A) We can use REPAIR command to repair a table. The REPAIR command will repair the table specified.
The syntex for repairing a mysql table is:
REPAIR TABLE tablename
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.
3) How can we get the properties of an image (size, type, width, height) using php image functions?
A) To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function
4) How can we take a backup of a mysql table and how can we restore it?
A) Create a full backup of your database:
shell> mysqldump tab=/path/to/some/diropt db_name
shell> mysqlhotcopy db_name /path/to/some/dir
The full backup file is just a set of SQL statements, so restoring it is very easy:
shell> mysql “.”Executed”;
5) What Is a Persistent Cookie and how it is different from Temporary cookie?
A) A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies are created as temporary cookies which stored only in the browser’s memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
Temporary cookies cannot be used for tracking long-term information.
Persistent cookies can be used for tracking long-term information.
Temporary cookies are safer because no programs other than the browser can access them.
Persistent cookies are less secure because users can open cookie files see the cookie values.
Read This Article: UI Developer Interview Questions
6) How To Get the Uploaded File Information in the Receiving Script?
A) Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:
$_FILES[$fieldName][‘name’] – The Original file name on the browser system.
$_FILES[$fieldName][‘type’] – The file type determined by the browser.
$_FILES[$fieldName][‘size’] – The Number of bytes of the file content.
$_FILES[$fieldName][‘tmp_name’] – The temporary filename of the file in which
The uploaded file was stored on the server.
$_FILES[$fieldName][‘error’] – The error code associated with this file upload.
The $fieldName is the name used in the
7) What is the difference between mysql_fetch_object and mysql_fetch_array?
A) MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array
8) 14. What are the different tables present in MySQL?
A) Total 5 types of tables we can create
9) How can we encrypt the username and password using PHP?
A) You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD(“Password”);
You can use the MySQL PASSWORD() function to encrypt username and password.
Example: INSERT into user (password, …) VALUES (PASSWORD($password”)), …);
10) How can we send mail using JavaScript?
A) No. There is no way to send emails directly using JavaScript.
But you can use JavaScript to execute a client side email program send the email using the “mailto” code.
Here is an example:
function myfunction(form)
return true;

Author: admin

Leave a Reply