1. Do you know what is PHP?

PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites. Even a non technical person can cretae sites using its CMS. WordPress, osCommerce are the famus CMS of php. It is also an object oriented programming language like java, C-sharp etc. It is very eazy for learning

2. Explain what is the use of "echo" in php?

It is used to print a data in the webpage, Example:
<?php echo 'Car insurance'; ?>
The following code print the text in the webpage

3. Explain what is the difference between Session and Cookie?

The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user's computers in the text file format. Cookies can not hold multiple variables, But Session can hold multiple variables. We can set expiry for a cookie, The session only remains active as long as the browser is open. Users do not have access to the data you stored in Session, Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking

4. How to select a database in PHP?


5. Tell me what is the use of mysql_real_escape_string() function?

It is used to escapes special characters in a string for use in an SQL statement

6. Do you know what is the use of rand() in php?

It is used to generate random numbers. If called without the arguments it returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 6 and 12 (inclusive), for example, use rand(6, 12). This function does not generate cryptographically safe values, and should not be used for cryptographic uses. If you want a cryptographically secure value, consider using openssl_random_pseudo_bytes() instead.

7. Tell us how to create an array of a group of items inside an HTML form?

We can create input fields with same name for "name" attribute with squire bracket at the end of the name of the name attribute, It passes data as an array to PHP.

☛ For instance:
<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyArray[]" />
<input name="MyArray[]" />

8. Explain me what are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

☛ Mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both.
☛ mysql_fetch_object ( resource result ) Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows
☛ mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

9. Tell me what is PEAR?

PEAR is a framework and distribution system for reusable PHP components. The project seeks to provide a structured library of code, maintain a system for distributing code and for managing code packages, and promote a standard coding style. PEAR is broken into three classes: PEAR Core Components, PEAR Packages, and PECL Packages. The Core Components include the base classes of PEAR and PEAR_Error, along with database, HTTP, logging, and e-mailing functions. The PEAR Packages include functionality providing for authentication, networking, and file system features, as well as tools for working with XML and HTML templates.

10. Tell me what does PEAR stands for?

PEAR means “PHP Extension and Application Repository”. it extends PHP and provides a higher level of programming for web developers.

Download Interview PDF

11. Tell me how comparison of objects is done in PHP5?

We use the operator ‘==' to test is two object are instanced from the same class and have same attributes and equal values. We can test if two object are refering to the same instance of the same class by the use of the identity operator ‘==='.

12. Tell me how can we display information of a variable and readable by human with PHP?

To be able to display a human-readable result we use print_r().

13. Do you know what is the difference between mysql_fetch_object() and mysql_fetch_array()?

The mysql_fetch_object() function collects the first single matching record where mysql_fetch_array() collects all matching records from the table in an array.

14. Tell me how can you pass a variable by reference?

To be able to pass a variable by reference, we use an ampersand in front of it, as follows $var1 = &$var2

15. Tell me how can we automatically escape incoming data?

We have to enable the Magic quotes entry in the configuration file of PHP.

16. How can we access the data sent through the URL with the GET method?

In order to access the data sent via the GET method, we you use $_GET array like this:

$variable = $_GET[“var”]; this will now contain ‘value'

17. Explain how is it possible to set an infinite execution time for PHP script?

The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded'.It is also possible to specify this in the php.ini file.

18. Tell me what is the meaning of a final class and a final method?

‘final' is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overrided.

19. Explain what are the different errors in PHP?

In PHP, there are three types of runtime errors, they are:

☛ Warnings:
These are important errors. Example: When we try to include () file which is not available. These errors are showed to the user by default but they will not result in ending the script.

☛ Notices:
These errors are non-critical and trivial errors that come across while executing the script in PHP. Example: trying to gain access the variable which is not defined. These errors are not showed to the users by default even if the default behavior is changed.

☛ Fatal errors:
These are critical errors. Example: instantiating an object of a class which does not exist or a non-existent function is called. These errors results in termination of the script immediately and default behavior of PHP is shown to them when they take place. Twelve different error types are used to represent these variations internally.

20. Tell me what are the encryption techniques in PHP?

☛ MD5 PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg);

☛ mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] );
Encrypts plaintext with given parameters

21. Tell me how to strip whitespace (or other characters) from the beginning and end of a string?

The trim() function removes whitespaces or other predefined characters from both sides of a string.

22. Explain me what is the use of 'print' in php?

This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.

print('PHP Interview questions');
print 'Job Interview ';

23. Explain me how to include a file to a php page?

We can include a file using "include() " or "require()" function with file path as its parameter.

24. Tell me what is the use of explode() function?

Syntax :
array explode ( string $delimiter , string $string [, int $limit ] );

This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.

Download Interview PDF

25. Tell me what are the different types of errors in PHP?

Here are three basic types of runtime 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 behavior.
☛ 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 behavior is to display them to the user when they take place.