php Interview Questions Mostly Asked To Freshers

Question : 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?
Answer : When to use GET or POST
The HTML 2.0 specification says, in section Form Submission (and the HTML 4.0 specification repeats this with minor stylistic changes):
–>If the processing of a form is idempotent (i.e. it has no lasting observable effect on the state of the
world), then the form method should be GET. Many database searches have no visible side-effects and make ideal applications of query forms.

–>If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.


How the form data is transmitted?
quotation from the HTML 4.0 specification
–> If the method is “get” – -, the user agent takes the value of action, appends a ? to it, then appends the form data set, encoded using the application/x-www-form-urlencoded content type. The user agent then traverses the link to this URI. In this scenario, form data are restricted to ASCII codes.
–> If the method is “post” –, the user agent conducts an HTTP post transaction using the value of the action attribute and a message created according to the content type specified by the enctype
attribute.


Quote from CGI FAQ
Firstly, the the HTTP protocol specifies differing usages for the two methods. GET requests should always be idempotent on the server. This means that whereas one GET request might (rarely) change some state on the Server, two or more identical requests will have no further effect.
This is a theoretical point which is also good advice in practice. If a user hits “reload” on his/her browser, an identical request will be sent to the server, potentially resulting in two identical database or guestbook entries, counter increments, etc. Browsers may reload a GET URL automatically, particularly if cacheing is disabled (as is usually the case with CGI output), but will typically prompt the user before re-submitting a POST request. This means you’re far less likely to get inadvertently-repeated entries from POST.
GET is (in theory) the preferred method for idempotent operations, such as querying a database, though it matters little if you’re using a form. There is a further practical constraint that many systems have built-in limits to the length of a GET request they can handle: when the total size of a request (URL+params) approaches or exceeds 1Kb, you are well-advised to use POST in any
case.
I would prefer POST when I don’t want the status to be change when user resubmits. And GET
when it does not matter.


Question : Who is the father of PHP and explain the changes in PHP versions?
Answer : Rasmus Lerdorf is known as the father of PHP.PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3 is the successor to PHP/FI 2.0 and is a lot nicer. PHP 4 is the current generation of PHP, which uses the Zend engine under the hood. PHP 5 uses Zend engine 2 which, among other things, offers many additional OOPs features.


Question : How can we submit a form without a submit button?
Answer : The main idea behind this is to use Java script submit() function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit() method to onclick, onchange events of different inputs and perform the form submission. you
can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites).


Question : In how many ways we can retrieve the data in the result set of
MySQL using PHP?
Answer : You can do it by 4 Ways
1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc


Question : What is the difference between mysql_fetch_object and
mysql_fetch_array?
Answer : mysql_fetch_object() is similar to mysql_fetch_array(), with one difference -
an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).


Question : What is the difference between $message and $$message?
Answer : It is a classic example of PHP’s variable variables. take the following example.
$message = “nilesh”;
$$message = “is a owner of http://phpgr.blogspot.in/ “;
$message is a simple PHP variable that we are used to. But the $$message is not a very familiar face. It creates a variable name $ nilesh with the value “is a moderator of PHPXperts.” assigned. break it like this${$message} => $nileshSometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically.


Question : How can we extract string ‘hotmail.com ‘ from a string raghav.cool@hotmail.com using regular expression of PHP?
Answer : preg_match(”/^http://.+@(.+)$/”,’raghav.cool@hotmail.com’,$found);
echo $found[1];


Question : How can we create a database using PHP and MySQL?
Answer : We can create MySQL Database with the use of mysql_create_db(“Database Name”).


Question : What are the differences between require and include, include_once and require_once?
Answer :
The include() statement includes and evaluates the specified file.The documentation below also applies to require(). The two constructs are identical in every way except how they handle
failure. include() produces a Warning while require() results in a Fatal Error. In other words, use
require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. The include_once() statement includes and evaluates the
specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be
included again. As the name suggests, it will be included just once.include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function
redefinitions, variable value reassignments, etc.


Question : Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?
Answer : Yes we can use include() more than one time in any page though it is not a very good practice.


Question : 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)) ?
Answer : Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
MyISAM is the default storage engine as of MySQL 3.23 and as a result if
we do not specify the table name explicitly it will be assigned to the
default engine.


Question : Functions in IMAP, POP3 AND LDAP?
Answer : You can find these specific information in PHP Manual.


Question : How can I execute a PHP script using command line?
Answer : As of version 4.3.0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface. 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.


Question : Suppose your Zend engine supports the mode . Then how can you
configure your PHP Zend engine to support mode ?
Answer : In php.ini file:
set
short_open_tag=on
to make PHP support


Question : Shopping cart online validation i.e. how can we configure Paypal,
etc.?
Answer : We can find the detail documentation about different paypal integration process at the following site PayPal PHP
SDK : http://www.paypaldev.org/


Question : What is meant by nl2br()?
Answer : 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
you” to your browser.

No comments:

Post a Comment