PHP Interview questions

PHP Questions

1. What is the difference between include and require in PHP?

They are identical in every aspect, but they perform error handling in different ways. The include() function generates a warning (which does not halt execution) while the require() function generates a fatal error (which stops execution immediately).

2. Difference between strstr and stristr in php ?

strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("","@") will return "".
stristr() is idential to strstr() except that it is case insensitive.

3.What are the different types of Errors in PHP?

1. Notices: These are trivial, non-critical errors that PHP
encounters while executing a script - for example,
accessing a variable that has not yet been defined. By
default, such errors are not displayed to the user at all -
although you can change this default behaviour.

2. Warnings: These are more serious errors - for example,
attempting to include() a file which does not exist. By
default, these errors are displayed to the user, but they
do not result in script termination.

3. Fatal errors: These are critical errors - for example,
instantiating an object of a non-existent class, or calling
a non-existent function. These errors cause the immediate
termination of the script, and PHP?s default behaviour is
to display them to the user when they take place.

4. Parse Error: When we make mistake in PHP code like,
semicolon or any unexpected symbol in code

4. How to detect what encoding is done on string in PHP?

We use Function


5.PHP Exception Handling

a. Try - A function using an exception should be in a "try" block. If the exception does not trigger, the code will continue as normal. However if the exception triggers, an exception is "thrown"

b. Throw - This is how you trigger an exception. Each "throw" must have at least one "catch"

c. Catch - A "catch" block retrieves an exception and creates an object containing the exception information

5.What is SQL Injection? and How to Prevent it?

a.Sql Injection is used to hack a Site , it can be prevented by mysql_real_escape_string() function of PHP.

6.Difference When single quotes and double quotes are used in php?

$str = ‘hello world’;

echo ‘$str this is my world.’;


Output will be:: $str this is my world.

In case of double quoted string…

$str = ‘hello world’;

echo “$str this is my world. “;


Output will be:: hello world this is my world.

7. Five Array functions(excluding sort) and five String functions?

Ajax Questions

1. Full form of Ajax?

"Asynchronous JavaScript and XML"

2. What is the main strength of AJAX? Or why and when should we use AJAX in web application?

And the most common answer is – "AJAX Retrieves the value from server without without refreshing or reloading the whole page"

But, the more perfect answer is – "AJAX is an asynchronous technology where others request are synchronous."

3. Difference Between synchronous and asynchronous ?

Cutting it Breaf, a program does not wait for response after requesting an asynchronous call whereas synchronous does so.

Here is a simple example –

function check_answer() {

var a=0;

a = getAnswer(“getanswer.php?id=10”);

if(a==1) {


} else {

alert(“not present”);



Here getAnswer() function sends a AJAX request to the server with “getanswer.php?id=10” url and the php file decides (from database may be) the answer and output/response as 1 or 0.

But, this function will not work properly. It will alert “not present” instead of “present”. And yes, that is for the asynchronous request.

The reason is – when a = getAnswer(“getanswer.php?id=10”); line is being executed program does not wait for the response of setAnswer() function. So, value of keep unchanged or set to null.

So, how should we work with asynchronous request?

Of course, using callback function. Callback function is that function which is triggered when the request completes to get the response (or as defined).

MySql Questions

1. What is Indexing ? Why is it used ?

Indexing is used to improve the speed of operations in a table.
The users are unable to see the indexes, they are just used to speed up queries
and will be used by Database Search Engine to locate records very fast.

Problem is : That when you update a table with an index, you have to update the index as well.
This means that if you are constantly updating, inserting and removing entries
in your table this could have a negative impact on performance.

2. What is stored procedure?

A stored procedure is simply some MySQL statement. Almost any valid MySQL can go inside a stored procedure, apart from few.

Advantage :
Stored procedure increases performance of application. Once created, stored procedure is compiled and stored in the database catalog. It runs faster than uncompiled SQL commands which are sent from application.

Disadvantage :
Stored procedures make the database server high load in both memory for and processors. Instead of being focused on the storing and retrieving data, you could be asking the database server to perform a number of logical operations or a complex of business logic which is not the well designed in database server.

3. How can we remove duplicate values from a table?

Ans. Using having and Groupby function in Mysql query (Obviously with the query example)

4. How to import highly heavy database to local machine?

Ans Using command Prompt :

In Windows :

Browse the path to bin.

C:\xampp\mysql\bin> mysql -u root -p new_db_name_in_local

Note : Sql file name_of_db_to_import.sql should be placed in \mysql\bin directory

In Linux :

$ zcat database.gz | mysql -u username -p database_name

4. How to optimize mysql queries

Ans Using Explain method.

CSS Questions

1.What happens if class with same name is being called in two different Style-Sheets And an Attribute from second file is being called where we want first file to be called?

Use !important

Drupal Questions

1.Are there any challenges you face when you move your Site from local to Live Server?

Very commonly faced problem can be with regards to Clean URL which does not work.
For which we have to enable Mod ReWrite in Apache Configuration
And place Rewrite All line in httpd.conf file .

Linux Commands Questions

Rename a file in Linux Command?

mv oldfile_name newfile_name

Jquery Questions

Describe the difference between .bind() and .live() methods in jQuery?

Both almost carry the same functionality however follow different DOM Structure.

$('a').bind('click', function() { alert("Test .bind ") });

This is the most straight forward binding method. jQuery scans the document for all $('a') elements and binds the alert function to each of their click events

$('a').live('click', function() { alert("Test . live ") });

jQuery binds the alert function to the $(document) element, along with 'click' and 'a' as parameters. Any time an event bubbles up to the document node, it checks to see if the event was a click and if the target element of that event matches the 'a' CSS selector. If both are true, the function executes.

The live method can also be bound to a specific element (or “context”) other than document, like this:

$('a', $('#container')[0]).live(...);

If You Think This Post has helped you buy us a Coffee :)

Make Donation

  • Other: $

Donate now