Monday, 3 June 2013

PHP interview questions and answers for 1 year experience

php interview questions and answers for 1 year experience

Question: What are the current versions of apache, php, and mysql?
PHP: 7.0.4 / March 3, 2016
Apache: 2.4.18 December 14, 2015
MySQL: 5.6.26 / July 24, 2015

Question: What are the different types of errors in php?
E_ERROR: A fatal error that causes script termination
E_WARNING: Run-time warning that does not cause script termination
E_ALL: Catches all errors and warnings
E_PARSE: Compile time parse error.
E_NOTICE: Run time notice caused due to error in code
E_USER_WARNING: User-generated warning message.
E_USER_ERROR: User-generated error message.
E_USER_NOTICE: User-generated notice message.
E_STRICT: Run-time notices.
E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error

Question: What is maximum size of a database in mysql?
Answer: Depend on Operating System

Question: What is meant by MIME?
Multipurpose Internet Mail Extensions. 

WWW ability to recognize and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. 

Question: What Is a Persistent Cookie?

Persistent cookie is a cookie which is permanently stored on user’s computer in a cookie file. They are used for tracking the user information of the users who are browsing from a very long time. They also have the drawbacks of being unsecure, as user can see the cookies which are saved on the computer. 

Question: How to set persistent Cookie?
There is no special way to set persistent cookies. Setting Cookies with an expiration date become persistent cookie.
setcookie( "cookieName", 'cookieValue', strtotime( '+30 days' ) );

Question: Can we send ajax request to other domain?
Answer: No, You can't send Ajax request if different protocal OR different host.
For Example, the following table gives an overview of typical outcomes for checks against the URL"".

Compared URLOutcomeReason
httpː// protocol and host
httpː// protocol and host
httpː// protocol and host but different port protocol host host (exact match required) host (exact match required)
httpː//'t usePort explicit. Depends on implementation in browser.

Question: How can PHP read the hash portion of the URL?
Answer: PHP can't read the hash portion of the URL
Here, PHP can not read the birthday

There is some by which you can get this value
get the value by javascript and then set to cookie or pass in ajax. See Example
var query = location.href.split('#'); 
document.cookies = 'hasValue=' + query[1];

Question: What Is difference between array_combine and array_merge?
array_combine give an array by combining two arrays($keyArray, $valueArray) and both $keyArray & $valueArray must have same number of elements. $keyArrays become keys of returning Array, $valueArray become values of returning Arrays.

array_merge gives an array by merging two array ($array1, $array2) and both can have different number of elements. $array1 and $array2 are added in returning array.

Question: What Is difference between Cookie and Session?
Cookie are stored in client side (e.g Browser) where as Session are stored in server side (tmp file of web server). Cookie can be added/update/delete from browser but session can't delete from browser. 
Session is depended on cookie. For example: When user login in website then session is created in webserver. To communicate the webserver with user, an cookie is created by the application. with use of this cookie-key, Server get to know that user is login OR not.

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

Question: How to store the uploaded file to the final location? move_uploaded_file( string filename, string destination)

Question: Explain mysql_error(). The mysql_error() message will tell us what was wrong with our mysql query.

Question: What is stdClass?
It is PHP generic empty class.
stdClass is used to create the new Object. For Example
$newObj = new stdClass();
$newObj->name='What is your name?';
$newObj->description='Tell me about yourself?';

stdClass Object
    [name] => What is your name?
    [description] => Tell me about yourself?
    [areYouInIndia] => 1


Poonam Gupta said...

Question:how to check current request is from CLI or web server?
if( php_sapi_name() === 'cli'){
echo "Request from command prompt (CLI)";
echo "Request from server";

ARUN KUMAR said...

Redirect sites to Maintaince.php
1) create a file Maintaince.php in root
2) create .htaccess file
3) add the following code in the .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ maintaince.php [NC,L]

ARUN KUMAR said...

Question: What is XMLHttpRequest?

Chirag Zinzuvadiya said...

What is the drawback of ajax ?

Durai said...

Ajax is play a vital role in php base web app's because now days user doesn't like the page loading , while use on ajax it make the result in efficient way without irritating the user . The only disavantage was ajax is based on javascript that's it no need to hit the f5 and backspace Frequently

Poonam Gupta said...

Following are the main drawback of ajax
1. Onload ajax request may slow the page.
2. Ajax request can leads to security issue
3. If any javascript issue comes, Ajax will stop working

Arun Kumar said...

How to download generated xml file by a php script

header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="xmlfile.xml"');
echo $xmlContents;die;

Anonymous said...

Question: What is the name of the “-->” operator in PHP?

Jaydeep Palariya said...

what is diffrence between jquery code and java script code?

Aakash Makwana said...

Java Script is a language, JQuery is a library
Code gets simpler after using JQuery

Kidzoofun said...

really healpfull ...thanks to web technology

Gaurav Singh said...

What is difference b/w overloading and overriding

hanuman kumar said...

two methods have same name then it is called as Overloading. If the arguments are also same then it is called as overriding

hanuman kumar said...

What is the difference between required(), required_once() and include() functions?

Vishnu Priya said...

require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.

Jitendra said...

Nice Article

Yashvant Gupta said...

very heplful site..awesome.

nitin bansude said...

This is very useful. Please add some OOPs questions also.


What is Encapsulation. With example

Anonymous said...

This is very useful.

Thank you!

alexawork said...

this is very useful

atal bihari said...

What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

Anonymous said...

mysql_fetch_array() fetch each row of a table as an array. it is combine of both numeric array and associative array. that means you can access the values like $a[0] or $a['name'] etc..

mysql_fetch_row() fetch each row also as an array but the keys are only numeric. ex: $a[1] etc...

mysql_fetch_object() fetch data as an object. exmpl: $row-> field_name;

Post a Comment