PHP interview questions and answers
1. What does a special set of tags <?= and ?> do in PHP?Ans:The output is displayed directly to the browser.
2. Who is the father of PHP ?
Ans:Rasmus Lerdorf is known as the father of PHP.
3. How i can get ip address?
Ans:We can use SERVER var $_SERVER['SERVER_ADDR']
and getenv("REMOTE_ADDR") functions to get the IP address.
4.How do you define a constant?Ans:Via define() directive, like define ("MYCONSTANT", 500);
5.How do you pass a variable by value?
Ans:Put an ampersand in front of it, like $a = &$val.
6.Will comparison of string "49" and integer 50 work in PHP?
Ans:Yes, internally PHP will cast everything to the integer type,
so numbers 49 and 50 will be compared.
7. I am trying to assign a variable the value of 0123, but it keeps
coming up with a different number, what’s the problem?
Ans:PHP Interpreter treats numbers beginning with 0 as octal.
8.What’s the difference between htmlentities() and htmlspecialchars()?
Ans:htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand.
htmlentities translates all occurrences of character sequences that have different meaning in HTML.
htmlentities translates all occurrences of character sequences that have different meaning in HTML.
9.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
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.Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"?
1.Numeric array-->A numeric array stores each array element with a numeric index.Ans:We can do it by 4 Ways
1. mysql_fetch_row. , 2. mysql_fetch_array , 3. mysql_fetch_object
4. mysql_fetch_assoc
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.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
12.What is use of header() function in php ?
Ans: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
13. Types of arrays in PHP?function for redirection of pages. It is important to notice that header() must
be called before any actual output is seen
Ans:In PHP, there are three kind of arrays:
2.Associative array-->An associative array, each ID key is associated with a value.
3.Multidimensional array-->In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.
14. What is difference between delete, truncate and drop in php myql?
delete table – will delete all records from the table only, but not an auto_increment. i.e,, the auto_increment counter does not get reset.
truncate table – will delete all records from the table and also rebuild the table, and resetting the auto_increment counts.
Drop the table- will drop the table structure as well as data
15. What is difference between echo and print?
echo is faster than print,
echo can execute more than 1 statements but print does not execute more than 1 statements
print can execute only a single statement.
echo — Output one or more strings
print — Output a string
print — Output a string
16. What is difference between split and explode?
split--Splits a string into array by regular expression.
( This function has been DEPRECATED as of PHP 5.3.0. )
split--Splits a string into array by regular expression.
( This function has been DEPRECATED as of PHP 5.3.0. )
explode--Split a string by string , Returns an array of strings.
16. What is implode and join?
implode-- Join array elements with a string
join — Alias of implode()
join() and implode() are aliases of each other and therefore don't have any differences.
17. The Difference Between Cookies and Sessions
The main difference between cookies and sessions is that cookies are
stored in the user's browser, and sessions are not. A cookie can keep
information in the user's browser until deleted. Sessions work instead
like a token allowing access and passing information while the user has
their browser open. The problem with sessions is that when you close
your browser you also lose the session. 18. Get the second highest salary in a MySQL employee table
1) SELECT * FROM emp WHERE sal= (SELECT MAX(sal) FROM emp WHERE sal< (SELECT MAX(sal) FROM emp))
2) SELECT max(sal) from emp where sal not in(select max(sal) from emp)
3) SELECT * FROM emp ORDER BY sal DESC LIMIT 1, 1
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.