Select Category 
 

PHP Interview Questions Answers

PHP Interview Question - 121 : -

What are "GET" and "POST"?

PHP Interview Answer - 121 : -

GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input."

Major Difference

In simple words, in POST method data is sent by standard input (nothing shown in URL when posting while in GET method data is sent through query string.

Ex: Assume we are logging in with username and password.

GET: we are submitting a form to login.php, when we do submit or similar action, values are sent through visible query string (notice ./login.php?username=...&password=... as URL when executing the script login.php) and is retrieved by login.php by $_GET['username'] and $_GET['password'].

POST: we are submitting a form to login.php, when we do submit or similar action, values are sent through invisible standard input (notice ./login.php) and is retrieved by login.php by $_POST['username'] and $_POST['password'].

POST is assumed more secure and we can send lot more data than that of GET method is limited (they say Internet Explorer can take care of maximum 2083 character as a query string).

 

PHP Interview Question - 122 : -

What are the differences between  mysql_fetch_array(),  mysql_fetch_object(),  mysql_fetch_row()?

PHP Interview Answer - 122 : -

mysql_fetch_array() -> Fetch a result row as a combination of associative array and regular array.
mysql_fetch_object() -> Fetch a result row as an object.
mysql_fetch_row() -> Fetch a result set as a regular array().
 

PHP Interview Question - 123 : -

What are the advantages of stored procedures, triggers, indexes?

PHP Interview Answer - 123 : -

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.
 

PHP Interview Question - 124 : -

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

PHP Interview Answer - 124 : -

eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.
 

PHP Interview Question - 125 : -

How can we send mail using JavaScript?

PHP Interview Answer - 125 : -

No. There is no way to send emails directly using JavaScript.

But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:

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

 

PHP Interview Question - 126 : -

Explain normalization concept?

PHP Interview Answer - 126 : -

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

 

PHP Interview Question - 127 : -

How can we submit form without a submit button?

PHP Interview Answer - 127 : -

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: <input type=button value="Save" onClick="document.form.submit()">
 

PHP Interview Question - 128 : -

What is the difference between mysql_fetch_object and mysql_fetch_array?

PHP Interview Answer - 128 : -

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array
 

PHP Interview Question - 129 : -

When are you supposed to use endif to end the conditional statement?

PHP Interview Answer - 129 : -

When the original if was followed by : and then the code block without braces.
 

PHP Interview Question - 130 : -

How can we change the data type of a column of a table?

PHP Interview Answer - 130 : -

How can we change the data type of a column of a table?
This will change the data type of a column:

ALTER TABLE table_name CHANGE colm_name same_colm_name [new data type]

 

PHP Interview Question - 131 : -

How can we know the count/number of elements of an array?

PHP Interview Answer - 131 : -

a) sizeof($array) - This function is an alias of count()
b) count($urarray) - This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will return 1.
 

PHP Interview Question - 132 : -

What is the default session time in php and how can I change it?

PHP Interview Answer - 132 : -

The default session time in php is until closing of browser