PHP Knowledge

1. Who is the father of PHP and explain the changes in PHP versions?
Rasmus Lerdorf for version changes go to
Marco Tabini is the founder and publisher of PHP architect.
2. What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?
Main differences between GET & POST methods are :

  • GET method is the default method for forms.
  • In the form posted with GET method, the passed variables and their values are shown in address bar.
  • Therefore, GET method is useful to Bookmark an URL.
  • But’ also there is limit on length of values of form elements passed.
  • GET method is not secure as navigated values are displayed in address bar.
  • Get method is not recommended in applications where user information security is required.
  • Data submitted by the GET method will be displayed in the browsers address field
  • GET method is mostly used for submitting a small amount and less sensitive data.
  • POST method does not display any content in the address bar so; complete bookmaking is not possible as that of GET method.
  • With the POST method, there is no limit on amount of data POSTED.
  • POST method is recommended where; there is issue of user-information security.
  • Data submitted by the POST method will not be displayed anywhere on the browser.
  • POST method is mostly used for submitting a large amount or sensitive data.
3. How can we submit a form without a submit button?
We can use a simple JavaScript code linked to an event trigger of any form field.
We can use the document.form.submit() function of javascript for submits the form.
4. In how many ways we can retrieve the data in the result set of mysql using PHP?
As individual objects so single record or as a set or arrays.
5. What is the difference between mysql_fetch_object and mysql_fetch_array?
MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.
6. What is the difference between $message and $$message?
They are both variables.
But $message is a variable with a fixed name. $$message is a variable who’s name is stored in $message.
For example, if $message contains “var”, $$message is the same as $var.
7. How can we extract string “” from a string “” using regular expression of PHP?
We can use the preg_match() function with “/.*@(.*)$/” as the regular expression pattern.

For example:


echo $data[1];
8. How can we create a database using PHP and mysql?
PHP: mysql_create_db ()
Mysql: create database;
9. What are the differences between require and include include_once?
File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once(). This will prevent problems with function redefinitions, variable value reassignments, etc.
10. Can we use include (“includefile.php”) two times in a PHP page “makeit.PHP”?
Yes, we can include.
11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?
Total 5 types of tables we can create
2. Heap
3. Merge
4. InnoDB
6. BDB

MyISAM is the default storage engine as of MySQL 3.23.

12. Functions in IMAP, POP3 AND LDAP?
13. How can I execute a PHP script using command line?
Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.
14. Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support
mode ?
If you change the line: short_open_tag = off in php.ini file. Then your php ZEND engine support only mode.
15. Shopping cart online validation i.e. how can we configure Paypal, etc.?
16. What is meant by nl2br ()?
nl2br — Inserts HTML line breaks before all newlines in a string.
string nl2br (string); Returns string with inserted before all newlines.
For example: echo nl2br(”god bless\n you”) will output “god bless \n you” to your Browser.
17. How many connections to MYSQL?
There are three connection to Mysql:
1. mysql_connect();
2. mysql_pconnect();
3. Socket connection using php.
18. How many ways we can retrieve data from MYSQL?
19. What is Active directory?
20. Explain about SESSION.
21. Explain abou COOKIES.
22. How we can write php variables in Javascript?
23. Describe MySQL JOIN.
24. What is Magic quotes?
When data transfer through the variable $_GET, $_POST, $_COOKIE and $_REQUEST then system automatically adding backslashes prefixes() to every single quotes, doube quotes and backslashes.

A single quotes ‘ coming as \’
A double quotes ” coming as \”
A backslash \ coming as \\

This is same as addslashes() function. To remove this backslashes from data we can use stripslashes() function.
magic_quotes_gpc() – is used to check the magic quotes are enabled or not.

No need to use addslashes() function around submitted variables and not have your SQL query fail.
We can skip adding slashes manually altogether to keep your code less cluttered.

When form submission data are sent back to the browser must have the slashes removed manually with a call to stripslashes().

This feature is officially deprecated as of PHP 5.3.0, and removed in PHP 6 due to security concerns.

25. What is Magic functions?
PHP reserves a function which name start with double underscore, its a magic function.
__sleep() same as serialize()
__wakeup() same as unserialize()
26. What is Magic constant?
In PHP there are various predefined constants,

1) __LINE__ : This constant is used to indicate the current line number of the file.
2) __DIR__ : This constant is used to indicate the current directory in which the file is present.
3) __FILE__ : This constant is used to indicate the full path of the file.
4) __CLASS__ : Returns the class name.
5) __FUNCTION__ : Returns the function name.
6) __METHOD__ : Returns the function name.
7) __NAMESPACE__ : Displays the namespace in which we are working.

27. Explain about addslashes and stripslashes?
28. How we can upload 10 MB files into the server?
29. Explain about Header function.
30. php mail function parameters.
31. What will happen if echo statement comes before a header function. How we can redirect to the page?
32. How we can insert an array in to a table?
33. Explain about serialization and unserialization.

Last updated on 10th October, 2010

Leave a Reply

Your email address will not be published. Required fields are marked *