Tuesday, April 10, 2012

Php Interview Questions and Answers

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

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

2 What are the differences between  mysql_fetch_array(),  mysql_fetch_object(),  mysql_fetch_row()? 
AnsAnswer 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.).

3 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? 
Ans=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.

4 Who is the father of PHP ?
Ans= Rasmus Lerdorf is known as the father of PHP.


What is the difference between $name and $$name? 
Ans=$name is variable where as $$name is reference variable 
like $name=sonia and $$name=singh so $sonia value is singh.

How can we submit a form without a submit button?
Ans=Java script submit() function is used for submit form without submit button
on click call document.formname.submit()

In how many ways we can retrieve the data in the result set of
MySQL using PHP?
Ans=We can do it by 4 Ways
1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object
4. mysql_fetch_assoc

What are the differences between Get and post methods.
Ans=There are some defference between GET and POST method 
1. GET Method have some limit like only 2Kb data able to send for request 
But in POST method unlimited data can we send 
2. when we use GET method requested data show in url but 
Not in POST method so POST method is good for send sensetive request

How can we extract string "pcds.co.in " from a string "http://info@pcds.co.in
using regular expression of PHP?
Ans=preg_match("/^http:\/\/.+@(.+)$/","http://info@pcds.co.in",$matches);
echo $matches[1];

10 How can we create a database using PHP and MySQL?
Ans=We can create MySQL database with the use of
mysql_create_db("Database Name");

11 What are the differences between require and include?
Ans=Both include and require used to include a file but when included file not found 
Include send Warning where as Require send Fatal Error .

12 Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"?
Ans= Yes we can use include("xyz.php") more than one time in any page. but it create a prob when xyz.php file contain some funtions declaration then error will come for already declared function in this file else not a prob like if you want to show same content two time in page then must incude it two time not a prob

13 

No comments:

Post a Comment