php interview questions part two

  1. What is PHP?  is a robust, server-side, open source scripting language. is also cross platform, which means you can execute PHP scripts on Unix, Linux, or an NT server.
    It is easy to learn and widely used web technologies.
  2. What’s the difference between include and require?
    Both functions are used for file inclusion but differ how they handle the exception.If file not found in case of include() a warning will be issued but execution will continue. while in case of require() fatal error issued and terminate the execution.
  3. Differences between GET and POST methods ?
    Both are used to send request to the server.In case of GET request only headers will be sent to the servers.Headers length of TCP/IP packet is fixed so we can’t send large amount of data by this method.Only 1024 bytes data can be transferred.But in case of POST method,the values are sent in the request body so can we transferred large amount of data by this method.GET is insecure as data is transferred through headers and can be seen by url of the request but POST is secure as data is not shown in url.
  4. How to declare an array in php?

    1
    2
    3
    4
    5
    6
    7
    <?php
      $array = array('Ram', 'Aman', 'Sohan');
      //or $array = array();
      $array[0]="Ram";
      $array[1]="Aman";
      $array[2]="Sohan";
    ?>
  5. What is the main difference between PHP 4 and PHP 5?
    In PHP4, Constructor have same name as the Class name but in PHP 5 funtion named __construct is introduced.
  6. What is use of in_array() function in php ?
    in_array() is used to find out that a value exists in an array or not.It return true if found otherwise false.
  7. How to define a cookie in PHP?
    Setcookie(“cookie_name”, “cookie_value”, expired_time_in_milliseconds);
    eg.
    Setcookie(“user_name”, “ram”, time()+3600);
    Here expired will be for an hour.
  8. What is final class and a final method?
    ‘final’ is introduced in PHP5. final class cannot be extended and a final method cannot be overridden.

    1
    2
    3
    4
    5
    6
    7
    <?php
    final class A{
    public void display(){
     echo "Hello,How are you?";
    }
    }
    //You can't do the following. class B extends A{}
  9. How to connect Mysql with PHP?
    mysql_connect(servername,username,password);
    e.g.
    mysql_connection(“localhost”,”root”,”1234″);
  10. What is of mysql_real_escape_string() function?
    It is used to escapes special characters in a string for use in an SQL statement.It prevents from SQL Injection.