PHP-Mysql Interview Questions

Posted on August 10, 2013 by Suresh Kamrushi in Mysql, PHP

Some PHP interview question i am sharing with you, which are really interesting and upgraded my knowledge. It might help you out…:)

1) Maximum length of HTTP GET request?
– Browser support minimum of 2KB to maximum of 8 KB like MSIE and Safari about 2KB, in Opera about 4KB and in Firefox about 8KB.

2) How to jump to a particular record set after fetching all the records form table?
bool mysql_data_seek ( resource $result , int $row_number );

3) How to store the session into the database
PHP provides session_set_save_handler() function that allows you override the default session mechanism. And it takes six arguments, each of which is a name of function.
session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.

Parameters: Open, Close, Read, Write, Destroy, GC (garbage collector)

4) In-built Exceptions functions available to use in PHP?
Following are the in-built functions available with Exception handling in PHP:

getMessage();          // message of exception
getCode();              // code of exception
getFile();                 // source filename
getLine();                // source line
getTrace();              // an array of the backtrace()
getPrevious();          // previous exception
getTraceAsString();  // formatted string of trace

5) Maximum values that can the store with SET Data type of mysql?
Mysql set can take zero or more values but at the maximum it can take 64 values

6) How do you find out what is the next auto increment id?
SHOW TABLE STATUS FROM DBName

7) What is the difference between SET and ENUM?
A SET is a string object that can have zero or more values.
A SET can have a maximum of 64 different members.
An enumeration can have a maximum of 65,535 elements.
If you set a SET column to an unsupported value, the value is ignored.
If you insert an invalid value into an ENUM (that is, a string not present in the list of allowed values), the empty string is inserted instead as a special error value.
If an ENUM column is declared to allow NULL, the NULL value is a legal value for the column, and the default value is NULL. If an ENUM column is declared NOT NULL, its default value is the first element of the list of allowed values.
Values from the list of allowable elements in the column specification are numbered beginning with
The index of the NULL value is NULL
The index value of the empty string error value is 0. This means that you can use the following     SELECT statement to find rows into which invalid ENUM values were assigned:
mysql> SELECT * FROM tbl_name WHERE enum_col=0;

8) Is there a query that will Prefix a 0 to a x amount of times?
Example: In my table i have column with 4 Digit number as 1234, now client want it to make six digit number (001234) without changing the numeric value, so is there any query that will update my table values to six digit number without affecting the values.

INT(6) UNSIGNED ZEROFIL
OR
update tableName set FieldName = LPAD(FieldName,6,’0′);

For more interview questions on Mysql you can visit: Deskbright

  Comments or questions are welcome