Friday 12 September 2014

PHP Technical Interview Questions and Answers

PHP Technical Interview Questions and Answers

How can we get the browser properties using PHP?
echo $_SERVER['HTTP_USER_AGENT'];
$browser=get_browser(null,true);
print_r($browser);


How can we register the variables into a session?
session_register($sessionVar);


How can we know the total number of elements of Array?
sizeof($arrayVarriable);
count($arrayVarriable);


How can we create a database using php?
mysql_create_db('database_name');


What are encryption functions in PHP?
CRYPT(), MD5()


How to store the uploaded file to the final location?
$fileName = $_FILES["uploaded_file"]["name"]; 
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"];

// Path and file name
$pathAndName = "uploads/".$fileName;

// Run the move_uploaded_file() function here
$moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
// Evaluate the value returned from the function if needed
if ($moveResult == true) {
    echo "File has been moved from $fileTmpLoc  to $pathAndName";
} else {
     echo "ERROR: File not uploaded successfully";
}


How to get Mysql Error while executing query through mysql_query?
$data = mysql_query("SELECT * FROM users");
if(IS_NULL($data)){
echo mysql_error();
}


How do you call a constructor for a parent class?
parent::constructor()


How to get full date with php using date function?
echo date('Y-m-d H:i:s'); //2014-09-12 20:08:05


What are the Formatting and Printing Strings available in PHP?
printf() Displays a formatted string
sprintf() Return a formatted string in a variable
fprintf() Prints a formatted string to a file
number_format() Formats numbers as strings


How can we find the number of rows in a result set using PHP?
$obj = mysql_fetch_obj(mysql_query("select count(*) as total from users"));
echo $obj->total;


Which is the latest version of PHP?
The latest stable version of PHP is 5.5.14 released at 27 June 2014 .


How we expire cookie?
setcookie($cookieName,$cookieValue,time()-60*60*60*24); //Just set the previous time


What is use of var_dump?
It gives the value of Boolean/ text / Array/Object with data type.


What is final class?
Once declared any class as final class, we can't override it in future.


How many types of errors in PHP?
  • Notice error
  • Warning error
  • Fatal error


What is a .htacces file?
.htaccess is a configuration file running on Apache server.


Is PHP compiler language?
No, It is interpreted Language.


What are web services in PHP?
Web services are the server which is used to store, process and deliver web pages to clients(Browsers like mozilla, IE, Chrome etc).


How can we change the time zones using PHP?
date_default_timezone_set('America/Los_Angeles');


What are access modifiers in php?
public,protected and private are the three types of access modifiers in php.




How can we destroy a session in PHP?
session_destroy();


What are default session time and path? Default session time in PHP is 1440 seconds(24 minutes). Default session save path id temporary folder i.e tmp


What is the syntax to send a mail in PHP?
mail ($to , $subject ,$message ,$headers, $parameters);


Give an example of ternary operator in PHP?
echo ($age >18) ? 'Matured' : 'Not Matured' ;