:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:         
  passwords:  

Interview Questions and answers for PHP [Part 4]

The General Php Interview Questions consists the most frequently asked questions in Php. This list of 100+ questions guage your familiarity with the Php platform. The q&a have been collected over a period of time from various blogs, forums and other similar Php sites

4.Php interview Questions Part[4]

    4.1 How can we know the number of days between two given dates using MySQL?
    4.2 How can we change the name of a column of a table?
    4.3 How can we change the data type of a column of a table?
    4.4 How can we know that a session is started or not?
    4.5 What is the difference between PHP4 and PHP5?
    4.6 What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
    4.7 What is meant by nl2br()?
    4.8 How can we encrypt and decrypt a data presented in a table using MySQL?
    4.9 How can I retrieve values from one database server and store them in other database server using PHP?
    4.10 What are the functions for IMAP
    4.11 What are encryption functions in PHP?
    4.12 What is the difference between htmlentities() and htmlspecialchars()?
    4.13 What is the functionality of the function htmlentities?
    4.14 How can we get the properties (size, type, width, height) of an image using php image functions?
    4.15 How can we increase the execution time of a php script?
    4.16 How To Read the Entire File into a Single String?
    4.17 How can we destroy the cookie?
    4.18 How many ways can we get the value of current session id?
    4.19 What’s the difference between include and require?
    4.20 Explain the ternary conditional operator in PHP?

4.1 How can we know the number of days between two given dates using MySQL?

Use DATEDIFF()
SELECT DATEDIFF(NOW(),'2006-07-01');


4.2 How can we change the name of a column of a table?

This will change the name of column:
ALTER TABLE table_name CHANGE old_colm_name new_colm_name


4.3 How can we change the data type of a column of a table?

This will change the data type of a column:s
ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type]


4.4 How can we know that a session is started or not?

A session starts by session_start() function.
This session_start() is always declared in header portion. it always declares first. then we write session_register().


4.5 What is the difference between PHP4 and PHP5?

PHP4 cannot support oops concepts and Zend engine 1 is used.
PHP5 supports oops concepts and Zend engine 2 is used.
Error supporting is increased in PHP5.
XML and SQLLite will is increased in PHP5.


4.6 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 and a numeric array.
mysql_fetch_object - 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.


4.7 What is meant by nl2br()?

nl2br() inserts a HTML tag
before all new line characters \n in a string. echo nl2br("god bless \n you"); output: god bless
you


4.8 How can we encrypt and decrypt a data presented in a table using MySQL?

You can use functions: AES_ENCRYPT() and AES_DECRYPT() like:
AES_ENCRYPT(str, key_str)
AES_DECRYPT(crypt_str, key_str)


4.9 How can I retrieve values from one database server and store them in other database server using PHP?

For this purpose, you can first read the data from one server into session variables. Then connect to other server and simply insert the data into the database


4.10 What are the functions for IMAP?

imap_body - Read the message body
imap_check - Check current mailbox
imap_delete - Mark a message for deletion from current mailbox
imap_mail - Send an email message


4.11 What are encryption functions in PHP?

CRYPT()
MD5()


4.12 What is the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars() - Convert some special characters to HTML entities (Only the most widely used) htmlentities() - Convert ALL special characters to HTML entities


4.13 What is the functionality of the function htmlentities?

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.


4.14 How can we get the properties (size, type, width, height) of an image using php image functions?

To know the image size use getimagesize() function
To know the image width use imagesx() function
To know the image height use imagesy() function


4.15 How can we increase the execution time of a php script?

By the use of void set_time_limit(int seconds) Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed. When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out


4.16 How To Read the Entire File into a Single String?

If you have a file, and you want to read the entire file into a single string, you can use the file_get_contents() function. It opens the specified file, reads all characters in the file, and returns them in a single string. Here is a PHP script example on how to file_get_contents():


4.17 How can we destroy the cookie?

Set the cookie in past


4.18 How many ways can we get the value of current session id?

session_id() returns the session id for the current session


4.19 What’s the difference between include and require?

It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.


4.20 Explain the ternary conditional operator in PHP?

Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.

Copyright 2007, Megasolutions Ltd