Tuesday, 5 January 2016

Best PHP interview questions and answers PART-1

Question

  1. Who is the father of PHP and explain the changes in PHP versions ?

Answer:- Rasmus Lerdorf is the father of php and the year was 1994. PHPFI introduce as Personal Home Page Form Interpretor in 1994, After that PHP HOME TOOLS introduced in 1996 PHP3 released in 1998 having features like accessing different database servers, protocols, supporting some object Orientation concepts. PHP4 released in 1999In 1999 PHP introduced again as PHP: HYPERTEXT PREPROCESSOR with the help of Zeev and Andy and also introduced PHP interpretor4 that name was Zend Engine-1, so that PHP4 have the Zend Engine-1, In 2003 introduce PHP5 with Zend Engine-2PHP5 in 2004 having features like constructors, destructors, interfaces, abstract classes, public private and protected variables.

Question

2. Submit form without a "submit" button?

Answer:- It's JavaScript you're wanting not PHP. <a href="javascript:document.formname.submit()">Link</a> where "formname" is the name of your form eg <form name="formname">

Question

  1. In how many ways we can retrieve the date in the result set of MySQL using PHP?

Answer:- It matters on how you want to call the date using PHP from MySQL, if I do understand what you are asking for. For example acquiring a UNIX timestamp that represents the current date and time, In PHP, use time() in MySQL use UNIX_TIMESTAMP() You could format the date using in PHP use date(), IN MYSQL, use DATE_FORMAT() If you are interested in all the ways to do that then I can't give you a definite answer as to how "how many ways" most probably 4 ways

  • Mysql_fetch_row 2.) Mysql_fetch_array 3.) Mysql_fetch_object 4.) Mysql_fetch_assoc

Question

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

Answer:- i. using strstr function Echo strstr(“http://info@abc.com”, ‘@’) or ii. using list and split functions list($first, $second)=split(“@”,”http://info@abc.com”,2) echo $second;

Question

  1. How can we create a database using PHP and MySQL?

Answer:- To create a database use the mysql_query() function to execute an SQL query like this

<?php include 'config.php'; include 'opendb.php';

$query = "CREATE DATABASE phpcake"; $result = mysql_query($query); include 'closedb.php'; ?>

Please note that the query should not end with a semicolon.

PHP also provide a function to create MySQL database, mysql_create_db(). This function is deprecated though. It is better to use mysql_query() to execute an SQL CREATE DATABASE statement instead like the above example.

If you want to create MySQL database using PHP mysql_create_db() function you can do it like this :

<?php include 'config.php'; include 'opendb.php'; mysql_create_db('phpcake');

include 'closedb.php'; ?>

Question

6. What are the different tables present in mysql, which type of table is generated when we are creating a table in thefollowing syntax: create table employee(eno int(2),ename varchar(10)) ? Answer:- Default type is MyISAM There are basically two types of tables in MYSQL:1. Transaction safe2. Non transaction safe Transaction safe consist of InnoDB, BDBNon transaction table includes ISAM, MYISAM, MERGE, memory(HEAP), Blackhole, and Archive Question 7. Name the Functions in IMAP, POP3 AND LDAP? Answer:- Examples of IMAP Functions: 1. imap_list : Read the list of mailboxes2. imap_open : Opens an IMAP stream to mailbox Examples of LDAP Functions: 1. ldap_connect : This will connect to the ldap server withthe given login credentials.2. ldap_search : By using this command we can search in ldaprecords.

Pop 3

Functions

Possible Responses, Mapped to Callbacks

pop3_connect connect, error
pop3_delete delete, error
pop3_list listStart, list, listComplete, error
pop3_listA listStart, list, listComplete, error
pop3_noop noop, error
pop3_pass pass, error
pop3_quit quit, error
pop3_reset reset, error
pop3_retrieve retrieveStart, retrieve, retrieveComplete, error
pop3_sendCommand sendCommandStart, sendCommand, sendCommandComplete, error
pop3_stat stat, error
pop3_top topStart, top, topComplete, error
pop3_uidList uidListStart, uidList, uidListComplete, error
pop3_uidListA uidListStart, uidList, uidListComplete, error
pop3_user user, error
pop3_xAuthList xAuthListStart, xAuthList, xAuthListComplete, error
pop3_xAuthListA xAuthListStart, xAuthList, xAuthListComplete, error
pop3_xSender xSender, error

 

Functions without Callbacks

Functions Without Callbacks

pop3_free pop3_setResponseSink
pop3_disconnect pop3_setTimeout
pop3_get_option pop3_set_option
pop3_initialize pop3Sink_free
pop3_processResponses pop3Sink_initialize
pop3_setChunkSize

Question

How can I execute a PHP script using command line?

Answer:- By using CLI (command line interface) On command prompt type : php filename

Question

What is meant by nl2br()?

Answer:- Returns a string with " inserted before all newlinesnl2br() inserts html in stringex:echo nl2br("God bless\nU");output : God bless

U

Question

Draw the architecture of Zend engine?

Answer:- The Zend Engine is the internal compiler and runtime engine used by PHP4. Developed by Zeev Suraski and Andi Gutmans, the Zend Engine is an abbreviation of their names. In the early days of PHP4, it Works as follow: The PHP script was loaded by the Zend Engine and compiled into Zend opcode. Opcodes, short for operation codes, are low level binary Instructions. Then the opcode was executed and the HTML generated sent to the client. The opcode was flushed from memory after execution. Today, there are a multitude of products and techniques to help you speed up this process.

Question

Difference between mysql_fetch_object and mysql_fetch_array ?

Answer:- Object is returned, instead of an array. In this you can access the data by the field names.

Question

Difference between GET and POST methods ?

Answer:- GET method have some limit like only 2kb data able to send for request but in POST method unlimited data we can send.

Question

What are the differences between require and include ?

Answer:- Include and require used to include a file but if included file not found include send warning where as require send Fatal Error.

Question

What is the difference between the functions unlink and unset ?

Answer:- Unlink() deletes the given file from the file system, whereas unset() makes a variable undefined.

Question

Tell about Array sorting functions ?

Answer:- sort(), arsort(), rsort(), unsort(), natsort(), array_multisort()

Question

How you can count number of elements of an array ?

Answer:- Sizeof($urarray) or count($urarray)

Question

How you can count number of Rows in a Table ?

Answer:- Select COUNT(*) FROM table;

Question

Define Mail function in PHP ?

Answer:- mail($to, $Subject, $Body, $Headers);

Question

Magic Methods in PHP ?

Answer:- Member functions available to All the instance of class. Start with “__”, need to be declared as Public.__construct(), __destruct(), __set(), __get(), __call(), __sleep(), __wakeup(), __isset(), __unset()

Question

What is Cookie ?

Answer:- A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP you can both create and retrieve cookie values.Setcookie(name, value, expire, path, domain);Time()+(86400*30) [86400=1day]

Question

What is Session ?

Answer:- A session is a way to store information in variables to be used across multiple pages. Unlike a cookie, the information is not stored on the user’s computer. When you work with an application, you open it, do some changes and then you close it, this is much like a session, the computer knows who you are. It knows when you start the application and when you end. But on the Internet there is one problem, the web server does not know who you are or what you do, because the HTTP address does not maintain state. Session variables solve this problem by storing user information to be used across multiple pages like username. By default, session variables last until the user closes the browser.

Question

Full Form of AJAX ?

Answer:- Asynchronous JavaScript and XML

Question

What are Hooks ?

Answer:- “Hooks” are a common scheme for implementing plugins/extensions.

Question

What is Module ?

Answer:- A Module is a separate unit of software or hardware. Typical characteristics of modular components include portability, which allows them to be used in a variety of systems and interoperability, which allows them to function with the components of other systems. The term was first used in architecture.

Question

3-Tier Architecture ?

Answer:-

1) Model

2) Controller

3) View

 

 

No comments:

Post a Comment