PHP Interview Question & Answer

1.Explain how to submit form without a submit button in PHP?

A form can be submitted in various ways without using submit button.

  • Submitting a form by selecting an option from drop down box with the invocation of onChange event
  • Using java script : document.form.submit();
  • Using header(“location:page.php”);

2.How can we increase the execution time of a php script?

Default time allowed for the PHP scripts to execute is 30s defined in the php.ini file. The function used is set_time_limit(int seconds). If the value passed is ‘0’, it takes unlimited time. It should be noted that if the default timer is set to 30 sec and 20 sec is specified in set_time_limit(), the script will run for 45 secs.

How can we increase the execution time of a php script?

The script execution time can be increased by

– Using sleep() function in PHP script

– Using set_time_limit() function

– The default limit is 30 seconds. The time limit can be set to zero to impose no time limit to pause.

3.What are the functions for IMAP?

IMAP is used for communicate with mail servers. It has a number of functions. Few of them are listed below:

  • Imap_alerts – Returns all the imap errors occurred
  • Imap_body – Reads the message body
  • Imap_check – Reads the current mail box
  • Imap_clearflag_full – Clears all flags
  • Imap_close – close and IMAP stream
  • Imap_delete – Delete message from current mailbox
  • Imap_delete_mailbox – Deletes a mailbox
  • Imap_fetchbody – Fetches body of message
  • Imap_fetchheader – Fetches header of message
  • Imap_headers – Returns headers for ALL messages
  • Imap_mail : send a mail
  • Imap_sort- Sorts imap messages

4.What is Type juggle in php?

Type Juggling means dealing with a variable type. In PHP a variables type is determined by the context in which it is used. If an integer value is assigned to a variable, it becomes an integer.
E.g. $var3= $var1 + $var2

Here, if $var1 is an integer. $var2 and $var3 will also be treated as integers.

5.What is the difference between mysql_fetch_object and mysql_fetch_array?

Mysql_fetch_object returns the result from the database as objects while mysql_fetch_array returns result as an array. This will allow access to the data by the field names. E.g. using mysql_fetch_object field can be accessed as $result->name and using mysql_fetch_array field can be accessed as $result->[name]

6.Explain the ways to retrieve the data in the result set of MySQL using PHP?

Ways to retrieve the data in the result set of MySQL using PHP

1. mysql_fetch_row($result):- where $result is the result resource returned from a successful query executed using the mysql_query() function.

$result = mysql_query(“SELECT * from students);
while($row = mysql_fetch_row($result))
{
Some statement;
}

2. mysql_fetch_array($result):- Return the current row with both associative and numeric indexes where each column can either be accessed by 0, 1, 2, etc., or the column name.

$row = mysql_fetch_array($result)

3. mysql_fetch_assoc($result): Return the current row as an associative array, where the name of each column is a key in the array.

$row = mysql_fetch_assoc($result)
$row[‘column_name’]

7.What is the difference between the functions unlink and unset in PHP?

The function unlink() is to remove a file, where as unset() is used for destroying a variable that was declared earlier.

8.What is Joomla in PHP?

Joomla is a content management system. Powerful online applications and web sites are build using Joomla. Joomla is an open source CMS tool. Clients can easily manage their web sites with minimal amount of instructions. It is highly extensible. Joomla runs off PHP or MySQL. Joomla is used to create, maintain a structured, flexible portal, add or edit content, changes the look and feel of the site. PHP scripting is used and persisted most of its data / information in MySQL database.unset() empties a variable or contents of file.

9.What is zend engine in PHP?

Zend engine is like a virtual machine and is an open source, and is known for its role in automating the web using PHP. Zend is named after its developers Zeev and Aandi. Its reliability, performance and extensibility has a significant role in increasing the PHP’s popularity. The Zend Engine II is the heart of PHP 5. It is an open source project and freely available under BSD style license.

10.What is the difference between Split and Explode in PHP?

The split() function splits the string into an array using a regular expression and returns an array.
Ex: split(:India:Pakistan:Srilanka); returns an array that contains India, Pakistan, Srilanka.

The explode() function splits the string by string.
Ex: explode(and India and Pakistan and Srilanka); returns an array that contains India, Pakistan, Srilanka.

11.What is the difference between echo and print statement in PHP?

Multiple expressions can be given in echo statement, where as print cannot take multiple expressions.
Echo does not have a return value, where as print returns a value indicating successful execution.
Echo is faster when compared with print.

12.What is CAPTCHA in PHP?

Captcha are images with some characters/ digits on it. One need to type the characters or digits in the text box for the purpose of submitting. This avoids automatic submitting by an operation by other programs or a robot.

13.What is difference between developing website using Java and PHP?

Both technologies are used for dynamic websites development.

PHP is an interpreter based technology where as java is compiler based(usually JSP).

PHP is open source where as JSP is not.

Web sites developed in PHP are much more faster compared to Java technology

Java is a distributed technology, which means N tier application can be developed, where as PHP is used only for web development.

14.How do you create sub domains using PHP?

Wild card domains can be used. Sub domains can be created by first creating a sub directory in the /htdocs folder. E.g. /htdocs/mydomain. Then, the host file needs to be modified to define the sub domain. If the sub domains are not configured explicitly, all requests should be thrown to the main domain.

15.How to upload files using PHP?

– Select a file from the form using <inupt type=”file”>

– Specify the path into which the file is to be stored.

– Insert the following code in php script to upload the file.

move_uploaded_file($_FILES[“file”][“tmp_name”], “myfolder/” . $_FILES[“file”][“name”]);

0