php-interview-questions-answers

Php Interview Questions and Answers – Part 3

1- What is the difference between CHAR and VARCHAR data types?

CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, “Hello!” will be stored as “Hello! ” in CHAR(10) column.

VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, “Hello!” will be stored as “Hello!” in VARCHAR(10) column.

2- How can we encrypt and decrypt a data present in a mysql table using mysql?

AES_ENCRYPT() and AES_DECRYPT()

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.

3- What is the functionality of MD5 function in PHP?

string md5(string)

It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal number.

4- How can I load data from a text file into a table?

The MySQL provides a LOAD DATA INFILE command. You can load data from a file. Great tool but you need to make sure that:

a) Data must be delimited

b) Data fields must match table columns correctly

5- What is meant by MIME?

Answer 1:

MIME is Multipurpose Internet Mail Extensions is an Internet standard for the format of e-mail. However browsers also uses MIME standard to transmit files. MIME has a header which is added to a beginning of the data. When browser sees such header it shows the data as it would be a file (for example image)

Some examples of MIME types:

audio/x-ms-wmp

image/png

application/x-shockwave-flash

Answer 2:

Multipurpose Internet Mail Extensions.

WWW’s ability to recognize and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. …

6- How can we know that a session is started or not?

A session starts by session_start() function.

This session_start() is always declared in header portion. it always declares first. then we write session_register().

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

Answer 1:

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().

Answer 2:

The difference between mysql_fetch_row() and mysql_fetch_array() is that the first returns the results in a numeric array ($row[0], $row[1], etc.), while the latter returns a the results an array containing both numeric and associative keys ($row[‘name’], $row[’email’], etc.). mysql_fetch_object() returns an object ($row->name, $row->email, etc.).

8- If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?

Session depends on browser. If browser is closed then session is lost. The session data will be deleted after session time out. If connection is lost and you recreate connection, then session will continue in the browser.

9- What is the difference between PHP4 and PHP5?

PHP4 cannot support oops concepts and Zend engine 1 is used.

PHP5 supports oops concepts and Zend engine 2 is used.

Error supporting is increased in PHP5.

XML and SQLLite will is increased in PHP5.

10- Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?

Yes we can include that many times we want, but here are some things to make sure of:

(including abc.PHP, the file names are case-sensitive)

there shouldn’t be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

11- What is meant by nl2br()?

Anwser1:

nl2br() inserts a HTML tag <br> before all new line characters n in a string.

echo nl2br(“god bless n you”);

output:

god bless<br>

you

12- In how many ways we can retrieve data in the result set of MYSQL using PHP?

mysql_fetch_array – Fetch a result row as an associative array, a numeric array, or both

mysql_fetch_assoc – Fetch a result row as an associative array

mysql_fetch_object – Fetch a result row as an object

mysql_fetch_row —- Get a result row as an enumerated array

13- What are the functions for IMAP?

imap_body – Read the message body

imap_check – Check current mailbox

imap_delete – Mark a message for deletion from current mailbox

imap_mail – Send an email message

14- What are encryption functions in PHP?

CRYPT()

MD5()

15- What is the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used)

htmlentities() – Convert ALL special characters to HTML entities

16- What is the functionality of the function htmlentities?

htmlentities() – Convert all applicable characters to HTML entities

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

17- How can we get the properties (size, type, width, height) of an image using php image functions?

To know the image size use getimagesize() function

To know the image width use imagesx() function

To know the image height use imagesy() function

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

By the use of void set_time_limit(int seconds)

Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

19- How to set cookies?

setcookie(‘variable’,’value’,’time’)

;

variable – name of the cookie variable

value – value of the cookie variable

time – expiry time

Example: setcookie(‘Test’,$i,time()+3600);

Test – cookie variable name

$i – value of the variable ‘Test’

time()+3600 – denotes that the cookie will expire after an one hour

Related Posts


One thought on “Php Interview Questions and Answers – Part 3

  1. Make Apps

    Thank you for a few other great publish. Exactly where different could everyone obtain that variety of information in that fantastic way of writing? I get a display in the future, using this program . at the search for this sort of information and facts.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *


*