Thursday, 19 June 2008
PHP interview questions, Part 1
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.interviewdoor.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 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?
PHP interview questions, Part 2
- How can we repair a MySQL table?
- What are the advantages of stored procedures, triggers, indexes?
- What is the maximum length of a table name, database name, and fieldname in MySQL?
- How many values can the SET function of MySQL take?
- What are the other commands to know the structure of table using MySQL commands except explain command?
- How many tables will create when we create table, what are they?
- What is the purpose of the following files having extensions 1) .frm 2) .myd 3) .myi? What do these files contain?
- What is maximum size of a database in MySQL?
- Give the syntax of Grant and Revoke commands?
- Explain Normalization concept?
- How can we find the number of rows in a table using MySQL?
- How can we find the number of rows in a result set using PHP?
- How many ways we can we find the current date using MySQL?
- What are the advantages and disadvantages of Cascading Style Sheets?
- What type of inheritance that PHP supports?
- 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 - What are the advantages/disadvantages of MySQL and PHP?
- What is the difference between GROUP BY and ORDER BY in Sql?
- What is the difference between char and varchar data types?
- What is the functionality of md5 function in PHP?
- How can I load data from a text file into a table?
- How can we know the number of days between two given dates using MySQL?
- How can we know the number of days between two given dates using PHP?
- How can we change the name of a column of a table?
- How can we change the name and data type of a column of a table?
- What are the differences between drop a table and truncate a table?
- 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?
- 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)?
- 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?
- 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)?
- What are the different ways to login to a remote server? Explain the means, advantages and disadvantages?
- 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 and give the URL (”http://www.yoursite.com /”) as a return result. Tags should also be matched if they contain other attributes than the HREF attribute.
- A select query over a large table runs very slow because of the growing number of entries in that table. What different measures could be taken to improve speed?
- A company wants to store their invoices in a database. They already have their customers and articles in that database. Both customer and article are each identified by an unique integer value. Please create the SQL statements for creating the necessary table(s) for storing the invoices in a MySQL database. An invoice should hold information like invoice number, customer, date, article(s) and quantity etc.
- For the database from the previous question, please give an SQL query which returns the invoice number of all invoices which contain the article with the number “1234″. The query should be able to run under a MySQL 4.0 database.
- How would you backup and restore a big MySQL database? What are the advantages of the approach which you have taken over the others?
- Create a PHP web script with the following attributes: on start, three HTML form elements are shown: an string input field, a checkbox field, a dropdown/pull down list with 5 elements and a submit button. On submission, the form should be redisplayed (while remaining all options/inputs as the user has selected/entered them). Additionally, the selections/inputs of the user should be displayed in text. Please solve this without the use of any external libraries.
- What is MIME?
- What is PEAR in PHP?
- How can I use the COM components in PHP?
- How can I load the DLLs dynamically?
- How many ways we can give the output to a browser?
- How can we know that a session is started or not?
- What is the default session time in PHP and how can I change it?
- What changes I have to done in PHP.ini file for file uploading?
- What are the differences between MySQL_fetch_array(), MySQL_fetch_object(), MySQL_fetch_row()?
- How can I set a cron and how can i execute it in Unix, Linux, and windows?
- Steps for the payment gateway processing?
- How many ways I can register the variables into session?
- Explain different types of errors in PHP (i.e. arguments in errorreporting function)?
- How many ways I can redirect a PHP page?
- List out different arguments in PHP header function?
- What type of headers have to add in the mail function in which file a attached?
- What is the difference between
- What are the differences between include() and include_once() functions?
- Describe the importance of database abstraction layers in PHP and database connection?
- Explain MySQL optimization?
- What is the difference between using copy() and move() function in PHP file uploading?
- What is the difference between Reply-to and Return-path in the headers of a mail function?
- Explain about Type Juggling in PHP?
- How can I get the only name of the current executing file?
- How can I embed a Java program in PHP file and what changes have to be done in PHP.ini file?
- How can I find what type of images that the PHP version supports?
- 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
PHP interview questions
- What does a special set of tags do in PHP? - The output is displayed directly to the browser.
- 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.
- 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.
- 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.
- How do you define a constant? - Via define() directive, like define ("MYCONSTANT", 100);
- How do you pass a variable by value? - Just like in C++, put an ampersand in front of it, like $a = &$b
- 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.
- When are you supposed to use endif to end the conditional statement? - When the original if was followed by : and then the code block without braces.
- 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.
- How do I find out the number of parameters passed into function? - func_num_args() function returns the number of parameters passed in.
- If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? - 100, it’s a reference to existing variable.
- What’s the difference between accessing a class method via -> and via ::? - :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.
- Are objects passed by value or by reference? - Everything is passed by value.
- How do you call a constructor for a parent class? - parent::constructor($value)
- What’s the special meaning of __sleep and __wakeup? - __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.
- Why doesn’t the following code print the newline properly? $str = ‘Hello, there.\nHow are you?\nThanks for visiting TechInterviews’;
print $str;
?>
Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n. - Would you initialize your strings with single quotes or double quotes? - Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.
- How come the code works, but doesn’t for two-dimensional array of mine? - Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.
- What is the difference between characters \023 and \x23? - The first one is octal 23, the second is hex 23.
- With a heredoc syntax, do I get variable substitution inside the heredoc contents? - Yes.
- I want to combine two variables together:
$var1 = 'Welcome to ';
$var2 = 'TechInterviews.com';What will work faster? Code sample 1:
$var 3 = $var1.$var2;
Or code sample 2:
$var3 = "$var1$var2";
Both examples would provide the same result - $var3 equal to "Welcome to TechInterviews.com". However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.
- For printing out strings, there are echo, print and printf. Explain the differences. - echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:
and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.
- I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP? - On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().
- What’s the output of the ucwords function in this example?
$formatted = ucwords("TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS");
print $formatted;What will be printed is TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS.
ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first. - What’s the difference between htmlentities() and htmlspecialchars()? - htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
- 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.
- So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()? - Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.
- How do you match the character ^ at the beginning of the string? - ^\^