PHP interview questions, Part 1

Feel free to post the answers and discuss the questions in the comments. Mizanur Rahman also posted some detailed answers on his blog.

  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. Who is the father of PHP and explain the changes in PHP versions?
  3. How can we submit a form without a submit button?
  4. In how many ways we can retrieve the date in the result set of mysql using PHP?
  5. What is the difference between mysql_fetch_object and mysql_fetch_array?
  6. What is the difference between $message and $$message?
  7. How can we extract string ‘techinterviews.com ‘ from a string ‘http://www.techinterviews.com’ using regular expression of PHP?
  8. How can we create a database using PHP and mysql?
  9. What are the differences between require and include, include_once?
  10. Can we use include (”techinterviews.php”) two times in a PHP page “makeit.PHP”?
  11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?
  12. Functions in IMAP, POP3 AND LDAP?
  13. How can I execute a PHP script using command line?
  14. Suppose your Zend engine supports the mode <? ?> Then how can u configure your PHP Zend engine to support <?PHP ?> mode ?
  15. Shopping cart online validation i.e. how can we configure Paypal, etc.?
  16. What is meant by nl2br()?
  17. Draw the architecture of Zend engine?
  18. What are the current versions of apache, PHP, and mysql?
  19. What are the reasons for selecting lamp (linux, apache, mysql, PHP) instead of combination of other software programmes, servers and operating systems?
  20. How can we encrypt and decrypt a data present in a mysql table using mysql?
  21. How can we encrypt the username and password using PHP?
  22. What are the features and advantages of object-oriented programming?
  23. What are the differences between procedure-oriented languages and object-oriented languages?
  24. What is the use of friend function?
  25. What are the differences between public, private, protected, static, transient, final and volatile?
  26. What are the different types of errors in PHP?
  27. What is the functionality of the function strstr and stristr?
  28. What are the differences between PHP 3 and PHP 4 and PHP 5?
  29. How can we convert asp pages to PHP pages?
  30. What is the functionality of the function htmlentities?
  31. How can we get second of the current time using date function?
  32. How can we convert the time zones using PHP?
  33. What is meant by urlencode and urldocode?
  34. What is the difference between the functions unlink and unset?
  35. How can we register the variables into a session?
  36. How can we get the properties (size, type, width, height) of an image using PHP image functions?
  37. How can we get the browser properties using PHP?
  38. What is the maximum size of a file that can be uploaded using PHP and how can we change this?
  39. How can we increase the execution time of a PHP script?
  40. How can we take a backup of a mysql table and how can we restore it. ?
  41. How can we optimize or increase the speed of a mysql select query?
  42. How many ways can we get the value of current session id?
  43. How can we destroy the session, how can we unset the variable of a session?
  44. How can we destroy the cookie?
  45. How many ways we can pass the variable through the navigation between the pages?
  46. What is the difference between ereg_replace() and eregi_replace()?
  47. What are the different functions in sorting an array?
  48. How can we know the count/number of elements of an array?
  49. What is the PHP predefined variable that tells the What types of images that PHP supports?
  50. How can I know that a variable is a number or not using a JavaScript?
  51. List out some tools through which we can draw E-R diagrams for mysql.
  52. How can I retrieve values from one database server and store them in other database server using PHP?
  53. List out the predefined classes in PHP?
  54. How can I make a script that can be bilanguage (supports English, German)?
  55. What are the difference between abstract class and interface?
  56. How can we send mail using JavaScript?

All done? Read the second set of interview questions on PHP, or leave comments below.

This entry was posted in Web dev. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

121 Comments on PHP interview questions, Part 1

  1. Tanvir Ahmad
    Posted 5/21/2007 at 9:47 pm | Permalink

    Answer of Question no 21
    In PHP you can generate hashes using the md5() and sha1 functions. md5() returns a 128-bit hash (32 hexadecimal characters), whereas sha1() returns a 160-bit hash (40 hexadecimal characters). For example:

    This code will output the following:

    Original string: PHP & Information Security
    MD5 hash: 88dd8f282721af2c704e238e7f338c41
    SHA-1 hash: b47210605096b9aa0129f88695e229ce309dd362


    In MySQL you can generate hashes internally using the password(), md5(), or sha1 functions. password() is the function used for MySQL’s own user authentication system. It returns a 16-byte string for MySQL versions prior to 4.1, and a 41-byte string (based on a double SHA-1 hash) for versions 4.1 and up. md5() is available from MySQL version 3.23.2 and sha1() was added later in 4.0.2.

    mysql> select PASSWORD( ‘PHP & Information Security’ );

  2. Nilay Anand
    Posted 6/2/2007 at 9:39 am | Permalink

    I do dislike questions that require one to have memorized functions and parameter orders. I always prefer people to prove what they know, rather than what they don’t know.
    The all above question need one to memorized PHP in depth.

  3. Rakesh Chandel
    Posted 6/11/2007 at 10:29 am | Permalink

    what function is used to free the resultset in php?
    what is the difference in trim() and chop()?

  4. rishi
    Posted 6/14/2007 at 5:09 am | Permalink

    answer:
    How can we swap two varaibles without using any intermediate variable?
    x and y are variables
    step 1: x=x+y
    step 2: y=x-y
    step 3: x=x-y

  5. Amol Bhavsar
    Posted 6/15/2007 at 1:50 am | Permalink

    Answer for Question 3 :
    You can submit form without Submit Button in Two ways :
    (1).Using images
    (2).Using Javascript : You can submit form using Javascript by first defining first functions and calling them on some events like “onClick”,”onBlur” etc.

  6. Amol Bhavsar ,Pune (PHP Developer)
    Posted 6/15/2007 at 1:59 am | Permalink

    Answer to question 1 :
    Main differences between GET & POST methods are :
    -GET method is the default method for forms.
    -In the form posted with GET method , the passed variables and their values are shown in address bar.
    -Therefore ,GET method is useful to BookMark an URL.
    -But’also there is limit on length of values of form elments passed.
    -GET method is not secure as navigated values are displayed in address bar.
    -Get method is not recommonded in applications where user information security is required.

    -POST method does not display any content in the address bar so,complete bookmarking is not possible as that of GET method .
    -With the POST method ,there is no limit on amount of data POSTED.
    -POST method is recommonded where ,there is issue of user-information security.
    -POST method is

  7. Niladri
    Posted 6/30/2007 at 9:22 am | Permalink

    Any one tell me what is outer - joining in mysql?

  8. Niladri
    Posted 6/30/2007 at 9:25 am | Permalink

    what is the difference between split() and explode() ?

  9. Niladri
    Posted 6/30/2007 at 9:27 am | Permalink

    What is the utility of GD Library ?

  10. Hitu Patel
    Posted 7/7/2007 at 1:38 am | Permalink

    49). What is the difference between ereg_replace() and eregi_replace()?

    eregi_replace — replace regular expression case insensitive
    ereg_replace — replace regular expression

  11. Hitu Patel
    Posted 7/7/2007 at 1:39 am | Permalink

    (3) .How can we submit a form without a submit button?

    (1) we can use the document.form.submit() function of javascript for submit the form.

  12. Hitu Patel
    Posted 7/7/2007 at 1:53 am | Permalink

    (16). nl2br — Inserts HTML line breaks before all newlines in a string

  13. Hitu Patel
    Posted 7/7/2007 at 1:57 am | Permalink

    (20). You can use the AES functions to store data in an encrypted form by modifying your queries:

    INSERT INTO t VALUES (1,AES_ENCRYPT(’text’,'password’));

    For Decriyption use AES_DECRYPT()

  14. Sumanta
    Posted 8/4/2007 at 2:21 am | Permalink

    How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’ using regular expression of PHP?

    Ans is: $url = http://info@abc.com;
    $domain = strstr($url, ‘@’, 1);
    echo $domain;

    It will print abc.com.

  15. Sumanta
    Posted 8/4/2007 at 2:34 am | Permalink

    Sorry for last comment.
    The actual answer is following:–

    $url = http://info@abc.com;
    $domain = strstr($url, ‘a’);
    echo $domain;

    It will print abc.com.

  16. Manokaran
    Posted 8/27/2007 at 9:05 am | Permalink

    Difference between Session and Cookie in PHP ?

    Session variables are stored in Server system.

    Cookie variables are stored in Client system.

  17. arijeet bannerjee
    Posted 11/23/2007 at 1:31 pm | Permalink

    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?
    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.
    2. Who is the father of php and explain the changes in php versions?
    Rasmus Lerdorf for version changes go to http://php.net/ Marco Tabini is the founder and publisher of php|architect.
    3. How can we submit from without a submit button?
    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. For example:
    4. How many ways we can retrieve the date in result set of mysql Using php?
    As individual objects so single record or as a set or arrays.
    5. What is the difference between mysql_fetch_object and mysql_fetch_array?
    MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.
    6. What is the difference between $message and $$message?
    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.
    7. How can we extract string ‘abc.com ‘ from a string ‘http://info@a…’ using regular _expression of php?
    We can use the preg_match() function with “/.*@(.*)$/” as the regular expression pattern. For example: preg_match(”/.*@(.*)$/”,”http://info@abc.com”,$data); echo $data[1];
    8. How can we create a database using php and mysql?
    PHP: mysql_create_db()
    Mysql: create database;
    9. What are the differences between require and include, include_once?
    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.
    10. Can we use include (”abc.php”) two times in a php page “makeit.php”?
    Yes we can include..
    11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following
    syntax: create table employee(eno int(2),ename varchar(10)) ?
    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.
    12. Functions in IMAP, POP3 AND LDAP?
    Please visit:
    http://fi2.php.net/imap
    http://uk2.php.net/ldap
    13. How can I execute a php script using command line?
    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.
    14. Suppose your ZEND engine supports the mode Then how can u configure your php ZEND engine to support mode ?
    If you change the line: short_open_tag = off in php.ini file. Then your php ZEND engine support only mode.
    15. Shopping cart online validation i.e. how can we configure the paypals?
    16. What is meant by nl2br()?
    nl2br — Inserts HTML line breaks before all newlines in a string string nl2br (string); Returns string with ” inserted before all newlines. For example: echo nl2br(”god bless\n you”) will output “god bless \n you” to your browser.
    17. Draw the architecture of ZEND engine?
    18. What are the current versions of apache, php, and mysql?
    PHP: php5.1.2
    MySQL: MySQL 5.1
    Apache: Apache 2.1
    19. What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?
    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.
    20. How can we encrypt and decrypt a data present in a mysql table using mysql?
    AES_ENCRYPT () and AES_DECRYPT ()
    21. How can we encrypt the username and password using php?
    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);
    22. What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
    One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns.
    For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.
    23. What are the differences between PROCEDURE ORIENTED LANGUAGES and OBJECT ORIENTED LANGUAGES?
    Traditional programming has the following characteristics:
    Functions are written sequentially, so that a change in programming can affect any code that follows it.
    If a function is used multiple times in a system (i.e., a piece of code that manages the date), it is often simply cut and pasted into each program (i.e., a change log, order function, fulfillment system, etc). If a date change is needed (i.e., Y2K when the code needed to be changed to handle four numerical digits instead of two), all these pieces of code must be found, modified, and tested.
    Code (sequences of computer instructions) and data (information on which the instructions operates on) are kept separate. Multiple sets of code can access and modify one set of data. One set of code may rely on data in multiple places. Multiple sets of code and data are required to work together. Changes made to any of the code sets and data sets can cause problems through out the system.
    Object-Oriented programming takes a radically different approach:
    Code and data are merged into one indivisible item – an object (the term “component” has also been used to describe an object.) An object is an abstraction of a set of real-world things (for example, an object may be created around “date”) The object would contain all information and functionality for that thing (A date
    object it may contain labels like January, February, Tuesday, Wednesday. It may contain functionality that manages leap years, determines if it is a business day or a holiday, etc., See Fig. 1). Ideally, information about a particular thing should reside in only one place in a system. The information within an object is encapsulated (or hidden) from the rest of the system.
    A system is composed of multiple objects (i.e., date function, reports, order processing, etc., See Fig 2). When one object needs information from another object, a request is sent asking for specific information. (for example, a report object may need to know what today’s date is and will send a request to the date object) These requests are called messages and each object has an interface that manages messages.
    OO programming languages include features such as “class”, “instance”, “inheritance”, and “polymorphism” that increase the power and flexibility of an object.
    24. What is the use of friend function?
    Friend functions
    Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class whichnames them as a friend, as if they were themselves members of that class.
    A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.

    class mylinkage
    {
    private:
    mylinkage * prev;
    mylinkage * next;
    protected:
    friend void set_prev(mylinkage* L, mylinkage* N);
    void set_next(mylinkage* L);
    public:
    mylinkage * succ();
    mylinkage * pred();
    mylinkage();
    };
    void mylinkage::set_next(mylinkage* L) { next = L; }
    void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }

    Friends in other classes
    It is possible to specify a member function of another class as a friend as follows:

    class C
    {
    friend int B::f1();
    };
    class B
    {
    int f1();
    };

    It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.

    class A
    {
    friend class B;
    };
    Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.
    25. What are the differences between public, private, protected, static, transient, final and volatile?
    element Class Interface
    Data field Method Constructor
    modifier top level nested top level nested
    (outer) (inner) (outer) (inner)
    final yes yes no yes yes no no
    private yes yes yes no yes no yes
    protected yes yes yes no yes no yes
    public yes yes yes yes yes yes yes
    static yes yes no no yes no yes
    transient yes no no no no no no
    volatile yes no no no no no no
    26. What are the different types of errors in php?
    Three are three types of errors:
    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, as you will see, you can change this default behaviour.
    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 behaviour is to display them to the user when they take place.
    27. What is the functionality of the function strstr and stristr?
    strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr(”user@example.com”,”@”) will return “@example.com”.
    stristr() is idential to strstr() except that it is case insensitive.
    28. What are the differences between PHP 3 and PHP 4 and PHP 5?
    Go read the release notes at http://php.net.
    29. How can we convert asp pages to php pages?
    You can download asp2php front-end application from the site http://asp2php.naken.cc.
    30. What is the functionality of the function htmlentities? 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.
    31. How can we get second of the current time using date function?
    $second = date(”s”);
    32. How can we convert the time zones using php?
    33. What is meant by urlencode and urldocode?
    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?
    unlink() deletes the given file from the file system.
    unset() makes a variable undefined.
    35. How can we register the variables into a session?
    We can use the session_register ($ur_session_var) function.
    36. How can we get the properties (size, type, width, height) of an image using php image functions?
    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
    37. How can we get the browser properties using php?
    38. What is the maximum size of a file that can be uploaded using php and how can we change this?
    You can change maximum size of a file set upload_max_filesize variable in php.ini file
    39. How can we increase the execution time of a php script?
    Set max_execution_time variable in php.ini file to your desired time in second.
    40. How can we take a backup of a mysql table and how can we restore it.?
    Answer: Create a full backup of your database: shell> mysqldump –tab=/path/to/some/dir –opt 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);
    42. How many ways can we get the value of current session id?
    ans:-
    session_id() returns the session id for the current session.
    43. How can we destroy the session, how can we unset the variable of a session?
    Ans:-
    session_unregister — Unregister a global variable from the current session
    session_unset — Free all session variables
    44. How can we destroy the cookie?
    Ans:-
    Set the cookie in past
    45. How many ways we can pass the variable through the navigation between the pages?
    Ans:-
    GET or QueryString and POST
    46. What is the difference between ereg_replace() and eregi_replace()?
    Ans:-
    eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.
    47. What are the different functions in sorting an array?
    Ans:-
    Sorting functions in PHP,
    asort-http://www.php.net/manual/en/function.asort.php
    arsort-http://www.php.net/manual/en/function.arsort.php
    ksort-http://www.php.net/manual/en/function.ksort.php
    krsort-http://www.php.net/manual/en/function.krsort.php
    uksort-http://www.php.net/manual/en/function.uksort.php
    sort-http://www.php.net/manual/en/function.sort.php
    natsort-http://www.php.net/manual/en/function.natsort.php
    rsort-http://www.php.net/manual/en/function.rsort.php
    48. How can we know the count/number of elements of an array?
    Ans:-
    2 ways
    a) sizeof($urarray) This function is an alias of count()
    b) count($urarray)
    interestingly if u just pass a simple var instead of a an array it will return 1.
    53. List out the predefined classes in php?
    Directory
    stdClass
    __PHP_Incomplete_Class
    exception
    php_user_filter
    54. How can I make a script that can be bilanguage (supports Eglish, German)?
    You can change charset variable in above line in the script to support bilanguage.
    55. What are the difference between abstract class and interface?
    Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.
    Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.
    56. How can we send mail-using JavaScript?
    NO! JavaScript can’t email a form! but, there are alternatives to send the form data to an email address.
    57. How can we repair a mysql table?
    The syntex for repairing a mysql table is
    REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]
    This command will repair the table specified if the quick is given the mysql will do a repair of only the index tree if the extended is given it will create index row by row
    58. What are the advantages of stored procedures, triggers, indexes?
    A stored procedure is a set of SQL commands that can be compiled and stored in the server. Once this has been done, clients don’t need to keep re-issuing the entire query but can refer to the stored procedure. This provides better overall performance because the query has to be parsed only once, and less information needs to be sent between the server and the client. You can also raise the conceptual level by having libraries of functions in the server. However, stored procedures of course do increase the load on the database server system, as more of the work is done on the server side and less on the client (application) side.
    Triggers will also be implemented. A trigger is effectively a type of stored procedure, one that is invoked when a particular event occurs. For example, you can install a stored procedure that is triggered each time a record is deleted from a transaction table and that stored procedure automatically deletes the corresponding customer from a customer table when all his transactions are deleted.
    Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.
    59. What is the maximum length of a table name, database name, and fieldname in mysql?
    Database name- 64
    Table name -64
    Fieldname-64
    60. How many values can the SET function of mysql takes?
    Mysql set can take zero or more values but at the maximum it can take 64 values
    61. What are the other commands to know the structure of table using mysql commands except explain command?
    describe table_name;
    62. How many tables will create when we create table, what are they?
    3 tables will create when we create table. They are
    The ‘.frm’ file stores the table definition.
    The data file has a ‘.MYD’ (MYData) extension.
    The index file has a ‘.MYI’ (MYIndex) extension,
    63. What is the purpose of the following files having extensions 1) frm 2) MYD 3) MYI. What these files contains?
    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,
    64. What is maximum size of a database in mysql?
    If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint.
    The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.
    The amount of available disk space limits the number of tables.
    MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits.
    The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB.
    The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system.
    Operating System File-size Limit
    Linux 2.2-Intel 32-bit 2GB (LFS: 4GB)
    Linux 2.4+ (using ext3 filesystem) 4TB
    Solaris 9/10 16TB
    NetWare w/NSS filesystem 8TB
    Win32 w/ FAT/FAT32 2GB/4GB
    Win32 w/ NTFS 2TB (possibly larger)
    MacOS X w/ HFS+ 2TB
    65. Give the syntax of Grant and Revoke commands?
    The generic syntax for grant is as following
    > GRANT [rights] on [database/s] TO [username@hostname] IDENTIFIED BY [password]
    now rights can be
    a) All privileges
    b) combination of create, drop, select, insert, update and delete etc.
    We can grant rights on all databse by using *.* or some specific database by database.* or a specific table by database.table_name
    username@hotsname can be either username@localhost, username@hostname and username@%
    where hostname is any valid hostname and % represents any name, the *.* any condition
    password is simply the password of user
    The generic syntax for revoke is as following
    > REVOKE [rights] on [database/s] FROM [username@hostname]
    now rights can be as explained above
    a) All privileges
    b) combination of create, drop, select, insert, update and delete etc.
    username@hotsname can be either username@localhost, username@hostname and username@%
    where hostname is any valid hostname and % represents any name, the *.* any condition
    66. Explain Normalization concept?
    The normalization process involves getting our data to conform to three progressive normal forms, and a higher level of normalization cannot be achieved until the previous levels have been achieved (there are actually five normal forms, but the last two are mainly academic and will not be discussed).
    First Normal Form
    The First Normal Form (or 1NF) involves removal of redundant data from horizontal rows. We want to ensure that there is no duplication of data in a given row, and that every column stores the least amount of information possible (making the field atomic).
    Second Normal Form
    Where the First Normal Form deals with redundancy of data across a horizontal row, Second Normal Form (or 2NF) deals with redundancy of data in vertical columns. As stated earlier, the normal forms are progressive, so to achieve Second Normal Form, your tables must already be in First Normal Form.
    Third Normal Form
    I have a confession to make; I do not often use Third Normal Form. In Third Normal Form we are looking for data in our tables that is not fully dependant on the primary key, but dependant on another value in the table
    67. How can we find the number of rows in a table using mysql?
    Answer: Use this for mysql
    >SELECT COUNT(*) FROM table_name;
    but if u r particular about no of rows with some special result
    do this
    >SELECT [colms],COUNT(*) FROM table_name [where u put conditions];
    68. How can we find the number of rows in a result set using php?
    Answer: for PHP

    $result = mysql_query($any_valid_sql, $database_link);
    $num_rows = mysql_num_rows($result);
    echo “$num_rows rows found”;
    69. How many ways we can we find the current date using mysql?
    SELECT CURDATE();
    CURRENT_DATE() = CURDATE()
    for time use
    SELECT CURTIME();
    CURRENT_TIME() = CURTIME()
    70. What are the advantages and disadvantages of CASCADE STYLE SHEETS?
    External Style Sheets
    Advantages
    Can control styles for multiple documents at once
    Classes can be created for use on multiple HTML element types in many documents
    Selector and grouping methods can be used to apply styles under complex contexts
    Disadvantages
    An extra download is required to import style information for each document
    The rendering of the document may be delayed until the external style sheet is loaded
    Becomes slightly unwieldy for small quantities of style definitions
    Embedded Style Sheets
    Advantages
    Classes can be created for use on multiple tag types in the document
    Selector and grouping methods can be used to apply styles under complex contexts
    No additional downloads necessary to receive style information
    Disadvantages
    This method can not control styles for multiple documents at once
    Inline Styles
    Advantages
    Useful for small quantities of style definitions
    Can override other style specification methods at the local level so only exceptions need to be listed in conjunction with other style methods
    Disadvantages
    Does not distance style information from content (a main goal of SGML/HTML)
    Can not control styles for multiple documents at once
    Author can not create or control classes of elements to control multiple element types within the document
    Selector grouping methods can not be used to create complex element addressing scenarios
    71. What type of inheritance that php supports? Answer: In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword ‘extends’.
    72. How can increase the performance of mysql select query?
    The structure of table view buyers is as follows
    +—————-+————-+——+—–+———+—————-+
    | Field | Type | Null | Key | Default | Extra |
    +—————-+————-+——+—–+———+—————-+
    | user_pri_id | int(15) | | PRI | NULL | auto_increment |
    | userid | varchar(10) | YES | | NULL | |
    +—————-+————-+——+—–+———+—————-+
    the value of user_pri_id the last row 2345 then What will happen in
    the following conditions
    Condition1: Delete all the rows and insert another row then What is the starting value for this auto incremented field user_pri_id ,
    Condition2: Delete the last row(having the field value 2345) and insert another row then What is the value for this auto incremented field user_pri_id
    In general, when you want to make a slow SELECT … WHERE query faster, the first thing to check is whether you can add an index. All references between different tables should usually be done with indexes. You can use the EXPLAIN statement to determine which indexes are used for a SELECT. See section 7.4.5 How MySQL Uses Indexes and section 7.2.1 EXPLAIN Syntax (Get Information About a SELECT).
    Some general tips for speeding up queries on MyISAM tables:
    To help MySQL optimize queries better, use ANALYZE TABLE or run myisamchk –analyze on a table after it has been loaded with data. This updates a value for each index part that indicates the average number of rows that have the same value. (For unique indexes, this is always 1.) MySQL will use this to decide which index to choose when you join two tables based on a non-constant expression. You can check the result from the table analysis by using SHOW INDEX FROM tbl_name and examining the Cardinality value. myisamchk –description –verbose shows index distribution information.
    To sort an index and data according to an index, use myisamchk –sort-index –sort-records=1 (if you want to sort on index 1). This is a good way to make queries faster if you have a unique index from which you want to read all records in order according to the index. Note that the first time you sort a large table this way, it may take a long time.
    In both cases let the value for auto increment field be n then next row will have value n+1 i.e. 2346
    73. What are the advantages/disadvantages of mysql and php?
    Both of them are open source software (so free of cost), support cross platform. php is faster then ASP and JSP.
    74. What is the difference between GROUP BY and ORDER BY in Sql?
    To sort a result, use an ORDER BY clause.
    The most general way to satisfy a GROUP BY clause is to scan the whole table and create a new temporary table where all rows from each group are consecutive, and then use this temporary table to discover groups and apply aggregate functions (if any).
    ORDER BY [col1],[col2],…,[coln]; Tels DBMS according to what columns it should sort the result. If two rows will hawe the same value in col1 it will try to sort them according to col2 and so on.
    GROUP BY [col1],[col2],…,[coln]; Tels DBMS to group results with same value of column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if you want to count all items in group, sum all values or view average
    75. What is the difference between char and varchar data types?
    char(M) M bytes 0
    80. How can we change the name of a column of a table?
    MySQL query to rename table: RENAME TABLE tbl_name TO new_tbl_name
    [, tbl_name2 TO new_tbl_name2] …
    or,
    ALTER TABLE tableName CHANGE OldName newName.
    81. How can we change the name and data type of a column of a table?
    ALTER [IGNORE] TABLE tbl_name
    alter_specification [, alter_specification] | CHANGE [COLUMN] old_col_name column_definition
    [FIRST|AFTER col_name]
    82. What are the differences between drop a table and truncate a table?
    Answer: Delete a Table or DatabaseTo delete a table (the table structure, attributes, and indexes will also be deleted).
    What if we only want to get rid of the data inside a table, and not the table itself? Use the TRUNCATE TABLE command (deletes only the data inside the table).
    83. When you want to show some part of a text displayed on an HTML page in red font color, what different possibilities are there to do this? What are the advantages/disadvantages of these methods?
    Using Html font color tag:
    I am Amin
    Using tag in CSS:
    STRONG {color:red}
    So when we use the tag:
    I am Amin about this.
    Using Class in CSS:

    .colorclass
    {
    color:#FF3399;
    font-weight:900;
    }

    I am Amin
    If we use html the modification will be trouble some because we have to change the code of the page. But when we use CSS then it will be easy to change the CSS file and we can get the desired out put.
    84. When viewing an HTML page in a Browser, the Browser often keeps this page in its cache. What can be possible advantages/disadvantages of page caching? How can you prevent caching of a certain page (please give several alternate solutions)?
    When you use the metatag in the header section at the beginning of an HTML Web page, the Web page may still be cached in the Temporary Internet Files folder.
    A page that Internet Explorer is browsing is not cached until half of the 64 KB buffer is filled. Usually, metatags are inserted in the header section of an HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the metatag is read, Internet Explorer looks for the existence of the page in cache at that exact moment. If it is there, it is removed. To properly prevent the Web page from appearing in the cache, place another header section at the end of the HTML ocument. For example:
    85. What are the different methods of passing data or information between two calls of a web page? What are the advantages/disadvantages of these methods?
    86. An Apache web server is running on a Linux system. Suddenly, the web server delivers the pages very slow. How could you find out possible reasons for that (when using system commands, please specify their names)?
    87. What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
    There is at least 3 ways to logon to a remote server:
    Use ssh or telnet if you concern with security
    You can also use rlogin to logon to a remote server.
    88. Please give a regular _expression (preferably Perl/PREG style), which can be used to identify the URL from within a HTML link tag. Example: The regular _expression should match the tag mysqldump -u user -ppassword –opt -full database_name > backupfile.sql
    Then move the resulting file(s) to your preferred backup areas. If you require more information on the mysqldump command, then simply check out this URL:www.mysql.com/documentation/mysql
    Copy all the relevant table files.
    If the server isn’t updating anything (or you’ve deliberately killed mysqld for this purpose) then you can copy all the files with the following extensions in your MySQL data directory:
    *.frm
    *.myd
    *.myi
    Make sure you restart the MySQL daemon once you finish copying and downloading the files to your preferred backup areas.
    TIP: once you’ve completed the backup, restart MySQL with the –log-update switch. This will allow you to keep track of all modifications done in the MySQL tables since your last ‘dump’.
    To restore your dumps, you should either restore to an existing database or create a new database using
    shell> mysqladmin create database_name
    then issue the following command :
    shell> mysql -u user -ppassword database_name
    94. What is meant by MIME?
    Multipurpose Internet Mail Extensions.
    WWW’s ability to recognise and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. …
    95. What is meant by PEAR in php?
    PEAR is short for “PHP Extension and Application Repository” and is pronounced just like the fruit. The purpose of PEAR is to provide:
    A structured library of open-sourced code for PHP users
    A system for code distribution and package maintenance
    A standard style for code written in PHP
    The PHP Foundation Classes (PFC),
    The PHP Extension Community Library (PECL),
    A web site, mailing lists and download mirrors to support the PHP/PEAR community
    PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.
    http://pear.php.net/manual/en/introduction.php
    96. How can I use the COM components in php?
    The COM class provides a framework to integrate (D)COM components into your PHP scripts.
    string COM::COM ( string module_name [, string server_name [, int codepage]])
    COM class constructor. Parameters:
    module_name
    name or class-id of the requested component.
    server_name
    name of the DCOM server from which the component should be fetched. If NULL, localhost is assumed. To allow DCOM com.allow_dcom has to be set to TRUE in php.ini.
    codepage
    specifies the codepage that is used to convert php-strings to unicode-strings and vice versa. Possible values are CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 and CP_UTF8.
    Usage:
    Version}\n”; //bring it to front $word->Visible = 1; //open an empty document $word->Documents->Add(); //do some weird stuff $word->Selection->TypeText(”This is a test…”); $word->Documents[1]->SaveAs(”Useless test.doc”); //closing word $word->Quit(); //free the object $word->Release(); $word = null; ?>
    97. How can I load the dlla€™s dynamically?
    98. How many ways we can give the output to a browser?
    HTML output
    PHP, ASP, JSP, Servlet Function
    Script Language output Function
    Different Type of embedded Package to output to a browser
    99. 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().
    100. What is the default session time in php and how can I change it?
    The default session time in php is until closing of browser
    101. What changes I have to done in php.ini file for file uploading?
    Make the following Line uncomment like:
    ; Whether to allow HTTP file uploads.
    file_uploads = On
    ; Temporary directory for HTTP uploaded files (will use system default if not
    ; specified).
    upload_tmp_dir = C:\apache2triad\temp
    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 2M
    102. 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, a numeric array, or both.
    mysql_fetch_object ( resource result )
    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.
    103. How can I set a cron and how can I execute it in Unix, Linux, and windows?
    Cron is very simply a Linux module that allows you to run commands at predetermined times or intervals. In Windows, it’s called Scheduled Tasks. The name Cron is in fact derived from the same word from which we get the word chronology, which means order of time.
    The easiest way to use crontab is via the crontab command.
    # crontab –e
    This command ‘edits’ the crontab. Upon employing this command, you will be able to enter the commands that you wish to run. My version of Linux uses the text editor vi. You can find information on using vi here.
    The syntax of this file is very important – if you get it wrong, your crontab will not function properly. The syntax of the file should be as follows:
    minutes hours day_of_month month day_of_week command
    All the variables, with the exception of the command itself, are numerical constants. In addition to an asterisk (*), which is a wildcard that allows any value, the ranges permitted for each field are as follows:
    Minutes: 0-59
    Hours: 0-23
    Day_of_month: 1-31
    Month: 1-12
    Weekday: 0-6
    We can also include multiple values for each entry, simply by separating each value with a comma.
    command can be any shell command and, as we will see momentarily, can also be used to execute a Web document such as a PHP file.
    So, if we want to run a script every Tuesday morning at 8:15 AM, our mycronjob file will contain the following content on a single line:
    15 8 * * 2 /path/to/scriptname
    This all seems simple enough, right? Not so fast! If you try to run a PHP script in this manner, nothing will happen (barring very special configurations that have PHP compiled as an executable, as opposed to an Apache module). The reason is that, in order for PHP to be parsed, it needs to be passed through Apache. In other words, the page needs to be called via a browser or other means of retrieving Web content.
    For our purposes, I’ll assume that your server configuration includes wget, as is the case with most default configurations. To test your configuration, log in to shell. If you’re using an RPM-based system (e.g. Redhat or Mandrake), type the following:
    # wget –help
    If you are greeted with a wget package identification, it is installed in your system.
    You could execute the PHP by invoking wget on the URL to the page, like so:
    # wget http://www.example.com/file.php
    Now, let’s go back to the mailstock.php file we created in the first part of this article. We saved it in our document root, so it should be accessible via the Internet. Remember that we wanted it to run at 4PM Eastern time, and send you your precious closing bell report? Since I’m located in the Eastern timezone, we can go ahead and set up our crontab to use 4:00, but if you live elsewhere, you might have to compensate for the time difference when setting this value.
    This is what my crontab will look like:
    0 4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php
    104. Steps for the payment gateway processing?
    An online payment gateway is the interface between your merchant account and your Web site. The online payment gateway allows you to immediately verify credit card transactions and authorize funds on a customer’s credit card directly from your Web site. It then passes the transaction off to your merchant bank for processing, commonly referred to as transaction batching
    105. How many ways I can register the variables into session?
    session_register(); $_SESSION[]; $HTTP_SESSION_VARS[];
    106. Explain different types of errors in php (i.e. arguments in error reporting function)?
    Three are three types of errors:
    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, as you will see, you can change this default behaviour.
    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 behaviour is to display them to the user when they take place.
    107. How many ways I can redirect a php page?
    Here are the possible ways of php page redirection.
    Using Java script:
    ‘; echo ‘window.location.href=”‘.$filename.’”;’; echo ”; echo ”; echo ”; echo ”; } } redirect(’http://maosjb.com’); ?>
    Using php function:
    Header(”Location:http://maosjb.com “);
    108. List out different arguments in php header function?
    void header ( string string [, bool replace [, int http_response_code]])
    109. What type of headers have to add in the mail function in which file a attached?

    $boundary = ‘—–=’ . md5( uniqid ( rand() ) );
    $headers = “From: \”Me\”\n”;
    $headers .= “MIME-Version: 1.0\n”;
    $headers .= “Content-Type: multipart/mixed; boundary=\”$boundary\”";
    110. What is the difference between and And which can be preferable?
    move_uploaded_file ( string filename, string destination)
    This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP’s HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.
    If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
    If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.
    116. What is the difference between Reply-to and Return-path in the headers of a mail function?
    Reply-to: Reply-to is where to delivery the reply of the mail.
    Return-path: Return path is when there is a mail delivery failure occurs then where to delivery the failure notification.
    117. Explain about Type Juggling in php?
    PHP does not require (or support) explicit type definition in variable declaration; a variable’s type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer.
    An example of PHP’s automatic type conversion is the addition operator ‘+’. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.

    $foo += 2; // $foo is now an integer (2)
    $foo = $foo + 1.3; // $foo is now a float (3.3)
    $foo = 5 + “10 Little Piggies”; // $foo is integer (15)
    $foo = 5 + “10 Small Pigs”; // $foo is integer (15)
    If the last two examples above seem odd, see String conversion to numbers.
    If you wish to change the type of a variable, see settype().
    If you would like to test any of the examples in this section, you can use the var_dump() function.
    Note: The behavior of an automatic conversion to array is currently undefined.
    Since PHP (for historical reasons) supports indexing into strings via offsets using the same syntax as array indexing, the example above leads to a problem: should $a become an array with its first element being “f”, or should “f” become the first character of the string $a?
    The current versions of PHP interpret the second assignment as a string offset identification, so $a becomes “f”, the result of this automatic conversion however should be considered undefined. PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above:
    118. How can I get the only name of the current executing file?
    119. How can I embed a java programme in php file and what changeshave to be done in php.ini file?
    There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.
    The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.
    Example Code:
    getProperty(’java.version’) . ”; echo ‘Java vendor=’ . $system->getProperty(’java.vendor’) . ”; echo ‘OS=’ . $system->getProperty(’os.name’) . ‘ ‘ . $system->getProperty(’os.version’) . ‘ on ‘ . $system->getProperty(’os.arch’) . ‘ ‘; // java.util.Date example $formatter = new Java(’java.text.SimpleDateFormat’, “EEEE, MMMM dd, yyyy ‘at’ h:mm:ss a zzzz”); echo $formatter->format(new Java(’java.util.Date’)); ?>
    The behaviour of these functions is affected by settings in php.ini.
    Table 1. Java configuration options
    Name
    Default
    Changeable
    java.class.path
    NULL
    PHP_INI_ALL
    Name Default Changeable
    java.home
    NULL
    PHP_INI_ALL
    java.library.path
    NULL
    PHP_INI_ALL
    java.library
    JAVALIB
    PHP_INI_ALL
    120. How can I find what type of images that the php version supports?
    Using Imagetypes() function we can know
    Usage:
    121. The table tbl_sites contains the following data.
    —————————————————–
    Userid sitename country
    ——————————————————
    1 sureshbabu indian
    2 phpprogrammer andhra
    3 php.net usa
    4 phptalk.com germany
    5 mysql.com usa
    6 sureshbabu canada
    7 phpbuddy.com pakistan
    8. phptalk.com austria
    9. phpfreaks.com sourthafrica
    10. phpsupport.net russia
    11. sureshbabu australia
    12. sureshbabu nepal
    13. phptalk.com italy
    Write a select query that will displayed the duplicated site name and how many times it is duplicated?
    SELECT sitename,
    COUNT(sitename) AS NumOccurrences
    FROM tbl_sites
    GROUP BY sitemail
    HAVING ( COUNT(sitemail) > 1 )
    Or
    SELECT sitename
    FROM tbl_sites
    GROUP BY sitename
    HAVING ( COUNT(sitename) = 1 )
    122. How can we send mail using JavaScript?
    No. You can’t send mail using Javascript. But you can execute a client side email client to send the email using mailto: code.
    Using clientside email client

    function myfunction(form)
    {
    tdata=document.myform.tbox1.value;
    location=”mailto:mailid@domain.com?subject=”+tdata+”/MYFORM”;
    return true; }
    }

  18. Janardhan
    Posted 1/21/2008 at 2:09 pm | Permalink

    Answer for Q4) is: In how many ways we can retrieve the date in the result set of mysql using PHP?

    In four ways: mysql_fetch_array, mysql_fetch_object, mysql_fetch_assoc, mysql_fetch_row.

  19. Posted 3/10/2008 at 4:18 am | Permalink

    Answer to question 3.
    submit a form without a submit button

    <input type=’image’ src=’imagepath.gif’ >
    or
    document.formname.submit();

  20. Frank
    Posted 4/20/2008 at 3:05 pm | Permalink
  21. mohamed
    Posted 6/22/2008 at 4:41 am | Permalink

    very very useful site…. most of the questions which was asked for my interview took from here only it seems… thanks a lot :)

2 Trackbacks

  1. [...] I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem? - PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems. [...]

  2. [...] Make sure you read Part 1 of PHP interview questions. For regular expressions, check out 8 Practical PHP Regular Expressions. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*