PHP Interview Questions

PHP Interview Questions (part-1)


  1. 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?
  2. On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.

    On the browser side, the difference is that data submitted by the GET method will be displayed in the browser's address field. Data submitted by the POST method will not be displayed anywhere on the browser.

    GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.
    Click Here to read more about GET & POST in PHP

  3. Who is the father of php and explain the changes in php versions?
  4. Rasmus Lerdorf
    For version changes go to http://php.net/ Marco Tabini is the founder and publisher of php|architect.

  5. How can we submit from without a submit button?
  6. We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form.

  7. How many ways we can retrieve the date in result set of mysql Using php?
  8. As individual objects so single record or as a set or arrays.

  9. What is the difference between mysql_fetch_object and mysql_fetch_array?
  10. MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.

  11. What is the difference between $message and $$message?
  12. 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.

  13. What are the differences between require and include, include_once?
  14. 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.

  15. What are the different tables present in mysql?
  16. Total 5 types of tables we can create

    1. MyISAM

    2. Heap

    3. Merge

    4. InnoDB

    5. ISAM

    6. BDB

    MyISAM is the default storage engine as of MySQL 3.23.

  17. How can I execute a php script using command line?
  18. 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.

  19. What is meant by nl2br()?
  20. Nl2br Inserts HTML line breaks before all newlines in a string string nl2br (string); For example: echo nl2br("god bless
    you") will output "god bless
    you" to your browser.

  21. What are the current versions of apache, php, and mysql?
  22. PHP: php 5.3
    MySQL: MySQL 5.5
    Apache: Apache 2.2

  23. What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?
  24. All of those are open source resource. Security of linux is very very more than windows. Apache is a better server that IIS both in functionality and security. Mysql is world most popular open source database. PHP is more faster that asp or any other scripting language.

  25. How can we encrypt and decrypt a data present in a mysql table using mysql?
  26. AES_ENCRYPT () and AES_DECRYPT ()

  27. How can we encrypt the username and password using php?
  28. You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password");
    We can encode data using base64_encode($string) and can decode using base64_decode($string);

  29. 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_PARSE: Compile time parse error.
    • E_NOTICE: Run time notice caused due to error in code
    • E_CORE_ERROR: Fatal errors that occur during PHP's initial startup (installation)
    • E_CORE_WARNING: Warnings that occur during PHP's initial startup
    • E_COMPILE_ERROR: Fatal compile-time errors indication problem with script.
    • E_USER_ERROR: User-generated error message.
    • E_USER_WARNING: User-generated warning message.
    • E_USER_NOTICE: User-generated notice message.
    • .E_STRICT: Run-time notices.
    • E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
    • E_ALL: Catches all errors and warnings

  30. What is the functionality of the function htmlentities?
  31. Answer: htmlentities Convert all applicable characters to HTML entities
    This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

  32. What is meant by urlencode and urldocode?
  33. Urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25?. URL encoded strings are safe to be used as part of URLs.
    urldecode() returns the URL decoded version of the given string.

  34. What is the difference between the functions unlink and unset?
  35. Unlink() deletes the given file from the file system.
    unset() makes a variable undefined.

  36. How can we register the variables into a session?
  37. We can use the session_register ($ur_session_var) function.

  38. How can we get the properties (size, type, width, height) of an image using php image functions?
  39. To know the Image type use exif_imagetype () function
    To know the Image size use getimagesize () function
    To know the image width use imagesx () function
    To know the image height use imagesy() function

  40. What is the maximum size of a file that can be uploaded using php and how can we change this?
  41. You can change maximum size of a file set upload_max_filesize variable in php.ini file.

  42. How can we increase the execution time of a php script?
  43. Set max_execution_time variable in php.ini file to your desired time in second.

  44. How can we take a backup of a mysql table and how can we restore it.?
  45. Create a full backup of your database: shell> mysqldump tab=/path/to/some/diropt db_name Or: shell> mysqlhotcopy db_name /path/to/some/dir
    The full backup file is just a set of SQL statements, so restoring it is very easy:


    shell> mysql "."Executed";
    mysql_close($link2);

  46. How many ways can we get the value of current session id?
  47. session_id() function returns the session id for the current session.

  48. How can we destroy the session, how can we unset the variable of a session?
  49. session_destroy and session_unset

Comments