Ask Your Question By Comment We Will Give You Better Solution Soon

Monday 20 January 2014

PHP Interview Questions With Answers

Q1. Who is the father of PHP and explain the changes in PHP versions?
Ans: Rasmus Lerdorf in 1994

Q2. How many ways you can retrieve the date in the result set of mysql using PHP?
Ans: We can do it by 4 Ways
         1. mysql_fetch_row. , 
         2. mysql_fetch_array ,
         3. mysql_fetch_object
         4. mysql_fetch_assoc 


Q3. How can we create a database using php and mysql?
Ans: <?php 
        $query  =mysql_query( "CREATE DATABASE phpcake");
        ?>
Q4. What is the difference between mysql_fetch_object and mysql_fetch_array? 
Ans: 1. object is returned, instead of an array
         2. In this you can only access the data by the field names

Q5. What are the differences between Get and post methods. 
Ans: GET Method have some limit like only 2Kb data able to send for request But in POST method                      unlimited data can we send.

Q6.  What are the differences between require and include? 
Ans: Include and require used to include a file but If included file not found Include send Warning where as            Require send Fatal Error .

Q7. What is the difference between the functions unlink and unset?
Ans: unlink() deletes the given file from the file system.
unset() makes a variable undefined.

Q8. What are the different functions in sorting an array?
 Ans: Sort(), arsort(),asort(), ksort(),natsort(), natcasesort(),rsort(), usort(),array_multisort(), and uksort().

Q9. How can we know the count/number of elements of an array? 
Ans:  a) sizeof($urarray) This function is an alias of count()
          b) count($urarray)

Q10. How can we find the number of rows in a table using MySQL? 
Ans: SELECT COUNT(*) FROM table_name;

Q11. 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);


Q12. what are magic methods?
Ans: Magic methods are the members functions that is available to all the instance of class Magic methods always starts with "__". Eg. __construct All magic methods needs to be declared as public To use magic method they should be defined within the class or program scope Various Magic Methods used in PHP 5 are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset() __unset() __autoload() __clone()

Q13. Email function in PHP?
Ans: <?php  $to = qualityzoneinfotech@gmail.com;
$subject = 'Qualityzoneinfotech.';
$body = "<p><strong>Heading...</strong> <br />
<strong>Custmer Name:</strong> <?php $name ;?> </p><br />
<strong>Custmer Email:</strong> <?php $email; ?>l </p><br />
<strong>Order Date:</strong> <?php date; ?>";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: Time2employment.com <qualityzoneinfotech@gmail.com>' . "\r\n";
$headers .= 'Cc: qualityzoneinfotech@gmail.com' . "\r\n";
mail($to, $subject, $body, $headers);
?>


Q14. What is the difference between session and cookies php..?
Ans : A session is always stored in the server. You lose all the session data once you close your browser, as every time you re-open your browser, a new session starts for any website.

A cookie is stored in the client’s browser.You can store almost anything in a browser cookie.


Q14. What is the difference between explode and cookies php..?
Ans :  Explode  : its used to skip the any sign or blank space in a string.
           $str = "Quality zone Infotech PVT LTD.";
          print_r (explode(" ",$str));

Implode : Its used for insert any character or space in string.
<?php
$arr = array('Hello','Quality','Zone','Infotech!');
echo implode(" ",$arr);
?>


No comments:

Post a Comment