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

  login:         
  passwords:  

Interview Questions and answers for PHP [Part 3]

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

3. Php Interview Questions Part[3]

    3.1 What Is a Session?
    3.2 What is meant by PEAR in php?
    3.3 How can we know the number of days between two given dates using PHP?
    3.4 How can we repair a MySQL table?
    3.5 How To Write the FORM Tag Correctly for Uploading Files?
    3.6 Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?
    3.7 WHAT IS THE FUNCTIONALITY OF THE FUNCTIONS STRSTR() AND STRISTR()?
    3.8 How do I find out the number of parameters passed into function9. ?
    3.9 What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?
    3.10 How do you call a constructor for a parent class?
    3.11 WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?
    3.12 What’s the difference between md5(), crc32() and sha1() crypto on PHP?
    3.13 How can we find the number of rows in a result set using PHP?
    3.14 How many ways we can we find the current date using MySQL?
    3.15 Give the syntax of GRANT commands?
    3.16 Give the syntax of REVOKE commands?
    3.17 What is the difference between CHAR and VARCHAR data types?
    3.18 How can we encrypt and decrypt a data present in a mysql table using mysql?
    3.19 Will comparison of string "10" and integer 11 work in PHP?
    3.20 What is the functionality of MD5 function in PHP? /a>

3.1 - What Is a Session?

A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests. There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.


3.2 What is meant by PEAR in php?

PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install "packages"


3.3How can we know the number of days between two given dates using PHP?

Simple arithmetic:
$date1 = date('Y-m-d');
$date2 = '2006-07-01';
$days = (strtotime() - strtotime()) / (60 * 60 * 24);
echo "Number of days since '2006-07-01': $days";


3.4 How can we repair a MySQL table?

The syntex for repairing a mysql table is:
REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED
This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.


3.5 How To Write the FORM Tag Correctly for Uploading Files?

When users clicks the submit button, files specified in the will be transferred from the browser to the Web server. This transferring (uploading) process is controlled by a properly written Note that you must specify METHOD as "post" and ENCTYPE as "multipart/form-data" in order for the uploading process to work. The following PHP code, called logo_upload.php, shows you a complete FORM tag for file uploading:


3.6 Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?

In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.


3.7 WHAT IS THE FUNCTIONALITY OF THE FUNCTIONS STRSTR() AND STRISTR()?

string strstr ( string haystack, string needle ) returns part of haystack string from the first occurrence of needle to the end of haystack. This function is case-sensitive. stristr() is idential to strstr() except that it is case insensitive


3.8 How do I find out the number of parameters passed into function9.?

func_num_args() function returns the number of parameters passed in.


3.9 -What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?

In MySQL, the default table type is MyISAM. Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.
The '.frm' file stores the table definition.
The data file has a '.MYD' (MYData) extension.
The index file has a '.MYI' (MYIndex) extension,


3.10 How do you call a constructor for a parent class?

parent::constructor($value)


3.11 Are The Differnt 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. Internally, these variations are represented by twelve different error types


3.12 What’s the difference between md5(), crc32() and sha1() crypto on PHP?

The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.


3.13 How can we find the number of rows in a result set using PHP?

Here is how can you find the number of rows in a result set in PHP:
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";


3.14 How many ways we can we find the current date using MySQL?

SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();


3.15 Give the syntax of GRANT commands?

The generic syntax for GRANT is as following
GRANT [rights] on [database] TO [username@hostname] IDENTIFIED BY [password]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.


3.16 Give the syntax of REVOKE commands?

The generic syntax for revoke is as following
REVOKE [rights] on [database] FROM [username@hostname]
Now rights can be:
a) ALL privilages
b) Combination of CREATE, DROP, SELECT, INSERT, UPDATE and DELETE etc.
We can grant rights on all databse by usingh *.* or some specific database by database.* or a specific table by database.table_name.


3.17 What is the difference between CHAR and VARCHAR data types?

CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column. VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.


3.18 How can we encrypt and decrypt a data present in a mysql table using mysql?

AES_ENCRYPT() and AES_DECRYPT()


3.19 Will comparison of string "10" and integer 11 work in PHP?

Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.


3.20 What is the functionality of MD5 function in PHP?

string md5(string)
It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.

Copyright 2007, Megasolutions Ltd