PHP Interview Questions

Level: Freshers

Q 61 - What are the correct and the most two common way to start and finish a PHP block of code?

The two most  common ways to start and finish a PHP script are:
Example: &nbsp; <br /> &nbsp;&nbsp; &nbsp; <em><!--?php</em--></em> <br /> <em>&nbsp;&nbsp; &nbsp;</em> <em><em>[ --PHP code--]</em></em> <br /> <em>&nbsp;&nbsp; &nbsp;</em> <em><em>?&gt;</em></em> <br /> <em>&nbsp;&nbsp; &nbsp;</em> <em>and</em> <br /> <em>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</em> <em><em><!--?</em--></em></em> <br /> <em><em>&nbsp;&nbsp; &nbsp;</em></em> <em><em><em>[ --PHP code--]</em></em></em> <br /> <em><em>&nbsp;&nbsp; &nbsp;</em></em> <em><em><em>?&gt;</em></em></em> <em><em>&nbsp; </em></em> <em><em>&nbsp;</em></em> &nbsp;

Q 62 - What does the initials of PHP stand for?

PHP means PHP: Hypertext Preprocessor.

Q 63 - What is the main difference between require() and require_once()?.

require() and require_once() perform the same task except that the second function checks if the PHP script is already included or not before executing it.
(same for include_once() and include()).

Q 64 - What does the PHP error ‘Parse error in PHP – unexpected T_variable at line x’ means?

This is a PHP syntax error expressing that a mistake at the line x stops parsing and executing the program.

Q 65 - How can we connect to a MySQL database from a PHP script?.

To be able to connect to a MySQL database, we must use mysql_connect() function as follows:
Example: database = mysql_connect(&quot;HOST&quot;, &quot;USER_NAME&quot;, &quot;PASSWORD&quot;); mysql_select_db(&quot;DATABASE_NAME&quot;,$database);

Q 66 - How can we check the value of a given variable is a number?

We can check any variable by using is_numeric() whether it is a number or not.

Q 67 - What does the unlink() function means?

The unlink() function is used to deleting the files from server.

Q 68 - What does the unset() function means?
 

The unset() function is used to unset any variable. It will make a variable undefined.

Q 69 - How a constant is defined in a PHP script?

The define() is used to efining a constant as follows:
Example: define (&ldquo;ACONSTANT&rdquo;, 123);

Q 70 - How is the ternary conditional operator used in PHP?

It is composed of three expressions: a condition, and two operands describing what instruction should be performed when the specified condition is true or false as follows:
Example: Expression_1 ? Expression_2 : Expression_3;<br /> &nbsp;

Q 71 - what is the definition of a session?

A session allow us to preserve temporary data across multiple PHP pages.
 

Q 72 - What is the difference between session_unregister() and session_unset()?

The session_unregister() function unregister a global variable from the current session and the session_unset() function free all session variables.

Q 73 - What is the difference between $_FILES[‘userfile’][‘name’] and $_FILES[‘userfile’][‘tmp_name’]?

$_FILES[‘userfile’][‘name’] represents the original name of the file on the client machine,
$_FILES[‘userfile’][‘tmp_name’] represents the temporary filename of the file stored on the server.

Q 74 - What is the default session time in php?

Typically the default is 24 minutes (1440 seconds).

Q 75 - Who is the father of PHP ?

Rasmus Lerdorf is known as the father of PHP.
 

Q 76 - What are the method available in form submitting?

GET and POST.

Q 77 - How to store the uploaded file to the final location?

move_uploaded_file( string filename, string destination).

Q 78 - What are the differences between Get and post methods.

There are some defference between GET and POST method
Example: <ul> <li>&nbsp;GET Method have some limit like only 2Kb data able to send for request</li> </ul> But in POST method unlimited data can we send. <ul> <li>&nbsp;when we use GET method requested data show in url but</li> </ul> Not in POST method so POST method is good for send sensetive request.

Q 79 - What is use of header() function in php ?

The header() function sends a raw HTTP header to a client.We can use herder()
function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen.
 

Q 80 - How can we find the number of rows in a result set using PHP?

$result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";