PHP Interview Question & Answer

PHP Interview Question and Answer


51. How to get the value of current session id?

session_id() function returns the session id for the current session.

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

o Mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both. o 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 o 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.

53. 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.

54. what is sql injection?

SQL injection is a malicious code injection technique.It exploiting SQL vulnerabilities in Web applications

55. What is x+ mode in fopen() used for?

Read/Write. Creates a new file. Returns FALSE and an error if file already exists

56. How to find the position of the first occurrence of a substring in a string

strpos() is used to find the position of the first occurrence of a substring in a string

57. 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.

58. Distinguish between urlencode and urldecode?

This method is best when encode a string to used in a query part of a url. it returns a string in which all non-alphanumeric characters except -_. have replece with a percentege(%) sign . the urldecode->Decodes url to encode string as any %and other symbole are decode by the use of the urldecode() function.

59. 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.

1 2 3 4 5 6