Sai Gopal Wordpress Blog

saigopal wordpress blog

Saigopal's website

Saigopal's website

My Daughter Website

Weebly

Palwow

Freelance Jobs

Saturday, June 19, 2010

PHP QUESTIONS AND ANSWERS

PHP QUESTIONS AND ANSWERS



what is the difference between ph4 and php5
Interview .com Answer
The main difference is PHP5 has much more focus on Object
Oriented Programming. In PHP5 you can pass functions by
reference, you can have abstract classes, interfaces etc.

Question
What is the difference between PHP,ASP and JSP?
Interview .com Answer
All 3 are Server Side scripting language of which

ASP is developed by microsoft, runs on IIS

JSP developer by Sun, runs on Apache Tomcat

PHP is open source, runs on Apache

Answer
All 3 are Server Side scripting language of which

ASP is developed by microsoft, runs on IIS. But its Slower than PHP

JSP developer by Sun, runs on Apache Tomcat, Slower than PHP but good for big level of projects

PHP is open source, runs on Apache, Faster than all and best for small and middle level of projects
Answer
Hi all, i just found one useful information about recent
questions on php,mysql,js and css.
http://imsrinivas.com/2010/06/most-recent-interview-questions-on-php-mysql-javascript-html-and-css/

Question
How to find second highest salary
© ALL Interview .com Answer
SELECT sallary FROM employee ORDER BY sallary ASC limit 1,2

Answer
SELECT salary FROM Employee_table ORDER BY salary DESC LIMIT 1,1

Answer
For Second Highest Salary:
select salary from tbl_name order by salary desc limit 1,1
For Third Highest Salary:
select salary from tbl_name order by salary desc limit 2,1
For Fourth Highest Salary:
select salary from tbl_name order by salary desc limit 3,1

Answer
select max(salary) from tbl_name where salary !=(select
max(salary) from tbl_name);

Answer
Select MAX(Salary) from tbl
order by salary DESC limit 1,1

Answer
if we want to make use of nested query instead of the above,
try the following

select max(column_name) from table_name where column_name =
(select
max(column_name)-(highest_salary_number_for_calculation -1)
from blocks where bid);

Example :

For second highest salary:

select max(bid) from blocks where bid = (select max(bid)-1
from blocks);

For third highest salary:

select max(bid) from blocks where bid = (select max(bid)-2
from blocks);
Prakash.matte
Answer
select salary from employee where max(salary)<(select salary from employee) Question how set session expire time in php? ALL Interview .com Answer go to php.ini , set the time limit for the session Answer unset("username" "timeout",60) Answer Question is not for ini file and not for unsetting, it is for changing the session life time from php file. ini_set("session.gc_maxlifetime", number_of_seconds); We can override the php.ini settings (if we don't have access) from php file using ini_set() Answer u feel u dont have access php.ini , then go with .http , make changes Question Want to know the 10th max salary in salary table ALL Interview .com Answer SELECT sal FROM salary SORT BY sal desc limit 9,1 Answer SELECT sal FROM salary ORDER BY sal DESC 9,1 Question what is the default session expire time in php? what is default file attachment size in mail in php? © ALL Interview .com Answer Default Session expire time is 24mins Default attachement size is 2mb both can be changed in php.ini file. Answer 40 minutes,5mb Siddharth [Upcilon] Question how much a fresher php programmer can earn in india Interview .com Answer i think not more than seven-ten thousand. Sumit Answer not more than 3.500 to 4000 Question How to convert any type of video formate in flv formate in php can any buddy give me coding. estion Submitted By :: om Answer check ffmpeg functions http://imsrinivas.com/2010/06/most-recent-interview-questions-on-php-mysql-javascript-html-and-css/ - www.tolance.com What is the method used to upload a file in html Enctype=”multipart/form-data Hi All, Recently i have attended interviews for several companies.its been very difficult to clear an interview for experienced [5+] persons.So i decided to prepare the list of questions[ im sorry i didnt come up with answers as of now] which is asked in my recent interviews.Im very new to blogging once i found the free time i will definitely add answers for these questions.I think this is very very useful information for web developers whoever preparing for the interviews. And these are the most recent and important questions perticulary interview panel expecting the answers from the candidate.So prepare well and all the very best.!! PHP 1)What is the diff between php4 and php5 ? 2)How to edit php ini settings without manual access ? 3)Diff between Abstract and Interface ? 4)How to access class function without instance ? 5)Is multiple inheritance supports in PHP ? 6)Diff between explode and split ? 7)Tell some CURL options ? 8)Diff between SOAP and REST ? 9)In Abstract class is it possible to give all methods as abstract methods? 10)Advantages of OOPS ? 11)Diff between explode and implode ? 12)What is include_once and require_once ? 13)How to add content at the end of the file using file functions ? 14)How to read cookie expiry time in php ? 15)What is HTTP ? 16)Diff between GET and POST, Where we can see the submited data in POST method ? 17)Tell me about Session 18)What is the default uploaded file size ? 19)How to parse XML ? 20)What is simpleXml ? 21)How to restrict the class to inherit from another class ? 22)What are the security issues in PHP ? 23)What is JSON ? 24)What is Cross site scripting ? 25)Syntax for preg_match ? 26)What is array_combine ? will it support in php4 ? 27)Overloading and overriding in php5 ? 28)Explain about magic methods in php5 29)What is autoload ? 30)If browser disables the cookie how to maintain session using php ? 31)What is call method ? 32)Optimisation in PHP 33)What is mod_rewrite ? 34)What is .htaccess and what is the use of this file ? 35)Caching in php 36)What is register_globals ? 37)What is polymorphism 38)What is the use of Interface 39)Tell few string function names 40)Explain about web services MySql 1)Tell me about Triggers and Storedprocedures. 2)About normalization ? 3)Diff between primary key and foriegn key 4)Diff between primary key and unique key 5)What is INDEX and how to create index 6)About joins 7)Diff between MyIsam and InnoDB 8)What are the different mysql engines 9)Diff between subquery and corelated query 10)Write a query to fetch secong largest salary taking employee frm emp table 11)Query for Export and Import data 12)Syntax for trigger and stored procedure HTML 1)Diff between Div and Span 2)What is DTD ? How many types are there Explain about all 3)Diff between HTML and XHTML 4)Optimisation in HTML CSS 1)Explain about box model 2)Diff between margin and padding 3)Diff types for positioning 4)Diff between position absolute and relative 5)What is float ? 6)CSS sprites 7)Optimisation in CSS 8)Diff between display inline and block 9)What is cascading 10)Image sprites 11)Conditional css 12)Diff types of styling css 13)What is the priority levels for diff types of css styling 14)Explaing about external and inline 15)What is import ? What are storage engines in mysql MyISAM Default engine as of MySQL 3.23 with great performance CSV CSV storage engine MRG_MYISAM Collection of identical MyISAM tables BLACKHOLE /dev/null storage engine (anything you write to it disappears) FEDERATED Federated MySQL storage engine InnoDB Supports transactions, row-level locking, and foreign keys ARCHIVE Archive storage engine MEMORY Hash based, stored in memory, useful for temporary tables PHP Sessions - Why Use Them? As a website becomes more sophisticated, so must the code that backs it. When you get to a stage where your website need to pass along user data from one page to another, it might be time to start thinking about using PHP sessions. Advertise on Tizag.com A normal HTML website will not pass data from one page to another. In other words, all information is forgotten when a new page is loaded. This makes it quite a problem for tasks like a shopping cart, which requires data(the user's selected product) to be remembered from one page to the next. PHP Sessions - Overview A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping cart items, etc). However, this session information is temporary and is usually deleted very quickly after the user has left the website that uses sessions. It is important to ponder if the sessions' temporary storage is applicable to your website. If you require a more permanent storage you will need to find another solution, like a MySQL database. Sessions work by creating a unique identification(UID) number for each visitor and storing variables based on this ID. This helps to prevent two users' data from getting confused with one another when visiting the same webpage. Note:If you are not experienced with session programming it is not recommended that you use sessions on a website that requires high-security, as there are security holes that take some advanced techniques to plug. Starting a PHP Session Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent. Below is a simple script that you should place at the beginning of your PHP code to start up a PHP session. PHP Code:
This tiny piece of code will register the user's session with the server, allow you to start saving user information and assign a UID (unique identification number) for that user's session.
Storing a Session Variable
When you want to store user data in a session use the $_SESSION associative array. This is where you both store and retrieve session data. In previous versions of PHP there were other ways to perform this store operation, but it has been updated and this is the correct way to do it.
PHP Code:

Display:
Pageviews = 1
In this example we learned how to store a variable to the session associative array $_SESSION and also how to retrieve data from that same array.
PHP Sessions: Using PHP's isset Function
Now that you are able to store and retrieve data from the $_SESSION array, we can explore some of the real functionality of sessions. When you create a variable and store it in a session, you probably want to use it in the future. However, before you use a session variable it is necessary that you check to see if it exists already!
This is where PHP's isset function comes in handy. isset is a function that takes any variable you want to use and checks to see if it has been set. That is, it has already been assigned a value.
With our previous example, we can create a very simple pageview counter by using isset to check if the pageview variable has already been created. If it has we can increment our counter. If it doesn't exist we can create a pageview counter and set it to one. Here is the code to get this job done:
PHP Code:

The first time you run this script on a freshly opened browser the if statement will fail because no session variable views would have been stored yet. However, if you were to refresh the page the if statement would be true and the counter would increment by one. Each time you reran this script you would see an increase in view by one.
Cleaning and Destroying your Session
Although a session's data is temporary and does not require that you explicitly clean after yourself, you may wish to delete some data for your various tasks.
Imagine that you were running an online business and a user used your website to buy your goods. The user has just completed a transaction on your website and you now want to remove everything from their shopping cart.
PHP Code:

You can also completely destroy the session entirely by calling the session_destroy function.
PHP Code:

Destroy will reset your session, so don't call that function unless you are entirely comfortable losing all your stored session data!

Question ID:
php
1
/ 54

Author: none
Question:
You can get PHP variables sent by a GET HTTP request by:



a)
using the $_GET["varname"]

b)
using the argv["varname"]

c)
a or b


d)
none of the above

Question ID:
PHP
38
/ 54

Author: palmer
Question:
PHP 5 comes with a Reflection API including several Reflection classes



a)
true (Correct answer)

b)
false

c)


d)

Question ID:
SQL
22
/ 28

Author: none
Question:
Which of the following will NOT have an effect on the performance SELECT queries? Assume that table employee has char last(50), char first(50)



a)
ANALYZE TABLE employee

b)
OPTIMIZE TABLE employee

c)
ALTER TABLE employee ADD INDEX(last(20),first(20));


d)
ENHANCE TABLE employee
(Correct answer)

Question ID:
css
11
/ 16

Author: none
Question:
What tag do you use for internal style sheets?


a)
style

b)
css

c)
body


d)
the name of the surround html tag fro that element
Correct

Question ID:
html
1
/ 32

Author: none
Question:
How do you let a javascript method execute on loading of an HTML document?



a)
event_listener( "onload", method() )

b)
the onload attribute inside body tag

c)
you cannot call javascript methods on a HTML page load


d)

Correct

Question ID:
Javascript
13
/ 30

Author: joe
Question:
How do you place a javascript function into an tag if you only want to execute that function?


a)
click me

b)
click me (Correct answer)

c)
click me


d)
click me





________________________________________

Question ID:
css
3
/ 16

Author: none
Question:
What is an inline style?


a)
is embedded in the element but applies to a class of elements

b)
is embedded at the top of the page in the style element and applies to the whole site

c)
is embedded at the top of the page in the style element and applies to the whole page



d)
applies to one specific element
Correct

Question ID:
bash
8
/ 15

Author: none
Question:
What kind of a process does the following bring into the foreground? fg %?abc


a)
end of the process name is ''abc''

b)
proces name starts with ''abc''

c)
the whole process name is ''abc''


d)
any part of the process name has ''abc''
Correct -> d

Question ID:
PHP
43
/ 54

Author: matsumodo
Question:
If $a and $b are arrays, What will happen to the following code?
$c = $a + $b


a)
error

b)
warning

c)
each of the elements of $a are added to each of the elements of $b, result goes into each element of $c


d)
$c will have the union of $a and $b
Correct -> d)
Question ID:
php
6
/ 54

Author: none
Question:
What is the difference between print and echo?


a)
almost no difference, both set return values, both can have multiple expression statements

b)
echo is a little faster because it does not set a return value though neither print or echo have multiple expression statements

c)
print is a little faster because it does not set a return value


d)
Echo can have Multiple Expression statements AND is a little faster because it does not set a return value
Correct -> d)




Question ID:
HTML
27
/ 32

Author: none
Question:
How do you make a hyperlink?



a)
http://www.codesplunk.com

b)
http://www.codesplunk.com

c)
codesplunk


d)
codesplunk
Correct -> d)
Question ID:
php
2
/ 54

Author: none
Question:
Which of the following is true about PHP with regards to XML


a)
PHP5 XML handling is not backwards compatible with PHP4 XML handling

b)
PHP5 XML and PHP4 XML are different but backwards compatible

c)
there is no difference between PHP5/PHP4 XML handling


d)
none of the above
Answer a



Question ID:
php
3
/ 54

Author: none
Question:
Which of the following PHP Settings is NOT specified in the php.ini file?


a)
the level of error/warning output

b)
allow or disallow short tags


b)

c)


d)
A or C will work
Correct answer a



Question ID:
PHP
22
/ 54

Author: rufus
Question:
What are the differences between require and include, include_once?



a)
require throws a fatal error if it cannot find the page it is trying to include

b)
include_once and require_once will include the page at most one time, even if called multiple times

c)
require checks to make sure all variables in the included file are declared, throws error otherwise


d)
A and B (Correct answer d)



Question ID:
PHP
23
/ 54

Author: rufus
Question:
What is PEAR?



a)
a library of open-sourced code for PHP users

b)
answer A and has a command-line interface that can be used to automatically install "packages"

c)
answer A,B and includes the PHP foundation classes (PFC)


d)
answer A,B,C and does not include web services libraries
(Correct answer C)

Question ID:
PHP
24
/ 54

Author: none
Question:
What is a reference variable?


a)
a variable that can be accessed through another variable ex: $a='b'; $$a is equal to $b

b)
a variable that is passed to a function parameter, copied both ways

c)
a variable who's address is passed through a function parameter


d)
a variable used to access an object or structure
Correct Answer a

Question ID:
PHP
25
/ 54

Author: none
Question:
How To Get the Uploaded File Information in the Receiving Script?



a)
through an object $_SERVER['FILES']

b)
through the two dimensional array $_UPLOAD

c)
through an object $_UPLOAD


d)
through a two dimensional array called $_FILES
(Correct answer is d)

Question ID:
PHP
26
/ 54

Author: none
Question:
Why do I keep getting the wrong number whenever I set the variable equal to a number that starts with zero? Like $a=0246;


a)
PHP treats numbers that start with a zero as trinary

b)
PHP treats numbers that start with a zero as binary

c)
PHP treats numbers that start with a zero as hexadecimal


d)
PHP treats numbers that start with a zero as octal
(Correct answer is d)

Question ID:
PHP
27
/ 54

Author: blomfeldsj
Question:
How do you pass by reference in PHP?


a)
variables are passed by reference by default

b)
place a

c)
place a # sign in front of the parameter


d)
place the reference keyword before the parameter
Correct answer b


Question ID:
PHP
28
/ 54

Author: none
Question:
What does urlencode do?


a)
returns a string that converts special characters into % signs followed by two hex digits

b)
codes the url into binary string

c)
codes the url into a nonhuman readable string that can be decoded by urldecode


d)
(Correct answer a)

Question ID:
PHP
29
/ 54

Author: none
Question:
How do I find out how many parameters were passed into a function?


a)
num_args()

b)
getArgc()

c)
func_num_args()


d)
you can't unless you check each of the values of the arguments
Correct answer is c



________________________________________

Question ID:
PHP
30
/ 54

Author: none
Question:
How do you call a constructor for a parent class?


a)
parent( $arg )

b)
parent.constructor( $arg )

c)
parent->constructor( $arg )


d)
parent::constructor( $arg )



Correct answer is d
________________________________________

Question ID:
PHP
31
/ 54

Author: none
Question:
What are the most ways you can pass a variable from page to page


a)
Session, Cookies, Save to Server (DB or file)

b)
Form (hidden input field), Pass it through the Url string

c)
Session, Save to Server, Cookies, Pass it through the Url string


d)
A and B
Correct answer is d


Question ID:
PHP
32
/ 54

Author: none
Question:
What are some of the top level library packages found in PEAR?


a)
Authentication, HTTP, Mail, System

b)
Benchmarking, Configuaration, Direct X, GUI

c)
Semantic Web, TCP/IP, UDP, ARP


d)
A and B

Correct answer is a


Question ID:
PHP
33
/ 54

Author: none
Question:
Which delimeters are PHP programs surrounded by?



a)


b)
...

c)



d)