Php Interview Question Answer
Thursday, 27 August 2015
Testing
- इलाबांस गांव के चार लोगों के खिलाफ मामला दर्ज - अवैध कब्जे से जल्द मुक्त होगी जमीन : रमा रमण जन प्रवाद, संवाददाता। नोएडा। नोएडा प्राधिकरण के अवसर अभियंता वर्क सर्किल-7 की ओर से नोएडा प्राधिकरण क्षेत्र के इलाबांस गांव के खसरा संख्या 178 एवं 179 की कुुल 19860 वर्ग मीटर भूमि (कीमत करीब 200 करोड़ रुपये) पर अवैध रूप से निर्माण एवं कब्जा करने के आरोप में इलाबांस निवासी हंशा, मंशा, राजे एवं जयकरन पुत्र बलवीर के खिलाफ कोतवाली फेस-दो में मामला दर्ज कराया गया है। प्राधिकरण के चेयरमैन\u0938ीईओ रमा रमण ने जानकारी दी है कि हंशा, मंशा, राजे एवं जयकरन पुत्र बलवीर निवासी इलाबांस प्राधिकरण की 19860 वर्ग मीटर भूमि पर अवैध रूप से कब्जा किए हुए हैं। उक्त जमीन की कीमत बाजार दर के अनुसार करीब 200 करोड़ रुपये है। यह जमीन प्राधिकरण की अर्जित एवं कब्जा प्राप्त भूमि है। प्राधिकरण की ओर से दिनांक 30 जुलाई 2015 को प्रश्नगत एवं अनाधिकृत जमीन को हटाने के लिए नोटिस दिया गया था। नोएडा प्राधिकरण की टीम जब 12 अगस्त 2015 को शाम करीब पांच बजे दिए गए ध्वस्तीकरण के नोटिस के क्रम में चिन्हीकरण के लिए गई तो हंशा, मंशा, राजे एवं जयकरन पुत्र स्व: बलवीर निवासी इलाबांस ने टीम पर जानलेवा हथियारों से लैस होकर हमला कर दिया। टीम के साथ गाली-गलौज करने के साथ ही जानलेवा हमला किया गया। प्राधिकरण टीम की विकास कार्यों से संबधित सरकारी फाइलों एवं अन्य दस्तावेजों को फाड़ते हुए नष्ट कर दिया गया था और कुछ सरकारी चीजों एवं निजी सामानों को लूट लिया गया। साथ ही जान से मारने की धमकी भी दी गई। उन्होंने आत्मदाह कर प्राधिकरण के अधिकारियों व कर्मचारियों को फंसाने की धमकी दी। रमा रमण ने बताया कि इलाबांस गांव की खसरा नंबर 178 एवं 179 की जमीन को भू-अर्जन अधिनियम 1894 की धारा 417 की अधिसूचना दिनांक 17 अप्रैल 2002 एवं धारा 617 की अधिसूचना 26 जून 2003 जारी हुई थी। इसके बाद दिनांक 28 फरवरी 2005 को नोएडा प्राधिकरण को विधिवत भौतिक कब्जा प्राप्त हो गया था। कोतवाली फेस दो पुलिस ने इलाबांस निवासी हंशा, मंशा, राजे एवं जयकरण पुत्र स्व. बलवीर के खिलाफ प्राधिकरण के अधिकारियों एवं कर्मचारियों को ब्लैकमेल करने, झूठे मुकदमों में फंसाने, मान माल की धमकी देने, अवैध निर्माण एवं कब्जा करने आपराधिक षड़यंत्र, सारकारी सामानों की लूटपाट करने आदि धाराओं में मामला दर्ज किया है। कोतवाली पुलिस ने 120बी, 146 147 148 149 309 332 353 356 390 446 447 448 499 500 503 504 आदि धाराओं में मामला दर्ज किया है। बॉक्स : इलाबांस की खसरा नंबर 179 एवं 179 की करीब 19860 वर्ग मीटर जमीन पर हंशा, मंशा, राजे एवं जयकरन पुत्र स्व. बलवीर ने अवैध रूप से कब्जा कर लिया है। इस जमीन की कीमत करीब 200 करोड़ रुपये है। शीघ्र ही पुलिस एवं पीएसी बल का प्रयोग करते हुए इस जमीन को खाली करवाया जाएगा। इसके लिए एसएसपी एवं जिला मजिस्ट्रेट ये यथा आवश्यक पुलिस बल एवं मजिस्ट्रेट की तैनाती का अनुरोध किया गया है। रमा रमण चेयरमैन\u0938ीईओ, नोएडा प्राधिकरणhttp://www.janpravad.com/News_Pic/1illegal_occupation_of_land_of_authority.png
Thursday, 20 February 2014
Java Script Interview Question Answer
How do we add JavaScript onto a web page?
Ans:There are several way for adding JavaScript on a web page, but there are two ways which are commonly used by developers
Code
<head>
<title>Page Title</title>
<script language="JavaScript" type="text/javascript">
var name = "Vikas Ahlawta"
alert(name);
</script>
</head>
Ques-Is JavaScript case sensitive?
Ans:Yes!A function getElementById is not the same as getElementbyID.
What is the difference between “==” and “===”?
Ans:“==” checks equality only,
“===” checks for equality as well as the type.
What are the ways of making comments in JavaScript?
Ans: // is used for line comments
ex:- var x=10; //comment text
/*
*/ is used for block comments
How will you get the Checkbox status whether it is checked or not?
var status = document.getElementById('checkbox1').checked;
alert(status);
How to create arrays in JavaScript?
There are two ways to create array in JavaScript like other languages:
a) The first way to create arrayDeclare Array:
var names = new Array();
Add Elements in Array:-
names[0] = "Vikas";
names[1] = "Ashish";
names[2] = "Nikhil";
b) This is the second way:
var names = new Array("Vikas", "Ashish", "Nikhil");
If an array with name as "names" contain three elements, then how will you print the third element of this array?
Print third array element
Note:- Array index starts with
document.write(names[2]); Note:- Array index starts with
0.
How do you submit a form using JavaScript?
Use
document.forms[0].submit();
What is an object in JavaScript, give an example?
An object is just a container for a collection of named values:
Example-
var man = new Object();
man.name = 'Vikas Ahlawat';
man.living = true;
man.age = 27;
How you will add function as a property in a JavaScript object? Give an example.
var man = new Object();
man.name = 'Vikas Ahlawat';
man.living = true;
man.age = 27;
man.getName = function() { return man.name;}
console.log(man.getName()); // Logs 'Vikas Ahlawat'.
Does JavaScript Support automatic type conversion, If yes give example.
Yes! Javascript support automatic type conversion. You should take
advantage of it, It is most common way of type conversion used by
Javascript developers.
Ex
var s = '5';
var a = s*1;
var b = +s;
typeof(s); //"string"
typeof(a); //"number"
typeof(b); //"number"
Java Script Interview Question Answer
1. What is JavaScript?
Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
16. How about 2+5+"8"?
We can declare an array like this
var scripts = new Array();
We can add elements to this array like this
19. How do you assign object properties?
20. What’s a way to append a value to an array?
21. What is this keyword?
That isnt what we want. We just want to wait until the DOM is loaded and is able to be manipulated. onDocumentReady allows the programmer to do that.
In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used......
JavaScript is a
platform-independent,event-driven, interpreted client-side scripting
language developed by Netscape Communications Corp. and Sun
Microsystems.
JavaScript is a
general-purpose programming language designed to let programmers of all
skill levels control the behavior of software objects. The language is
used most widely today in Web browsers whose software objects tend to
represent a variety of HTML elements in a document and the document
itself.
But the
language is used with other kinds of objects in other environments. For
example, Adobe Acrobat Forms uses JavaScript as its underlying scripting
language to glue together objects that are unique to the forms
generated by Adobe Acrobat.
Therefore, it
is important to distinguish JavaScript, the language, from the objects
it can communicate with in any particular environment.
When used for
Web documents, the scripts go directly inside the HTML documents and are
downloaded to the browser with the rest of the HTML tags and content.
2. How is JavaScript different from Java?
Don't be fooled by the term Java in both. Both are quite different technologies.
JavaScript was
developed by Brendan Eich of Netscape; Java was developed at Sun
Microsystems. While the two languages share some common syntax, they
were developed independently of each other and for different audiences.
Java is a full-fledged programming language tailored for network
computing; it includes hundreds of its own objects, including objects
for creating user interfaces that appear in Java applets (in Web
browsers) or standalone Java applications. In contrast, JavaScript
relies on whatever environment it's operating in for the user interface,
such as a Web document's form elements.
JavaScript was
initially called LiveScript at Netscape while it was under development. A
licensing deal between Netscape and Sun at the last minute let Netscape
plug the "Java" name into the name of its scripting language.
Programmers use entirely different tools for Java and JavaScript. It is
also not uncommon for a programmer of one language to be ignorant of the
other. The two languages don't rely on each other and are intended for
different purposes. In some ways, the "Java" name on JavaScript has
confused the world's understanding of the differences between the two.
On the other hand, JavaScript is much easier to learn than Java and can
offer a gentle introduction for newcomers who want to graduate to Java
and the kinds of applications you can develop with it.
3. What is the official JavaScript website?
This is a trick
question used by interviewers to evaluate the candidate’s knowledge of
JavaScript. Most people will simply say javascript.com is the official
website.
The truth is-
there is no official website for Javascript you can refer to. It was
developed by Brendan Eich for Netscape. It was based on the ECMAScript
language standard; ECMA-262 being the official JavaScript standard.
4. What’s relationship between JavaScript and ECMAScript?
ECMAScript is
yet another name for JavaScript (other names include LiveScript). The
current JavaScript that you see supported in browsers is ECMAScript
revision 3.
5. What are the various datatypes in javascript?
Number
String
Boolean
Function
Object
Null
Undefined
String
Boolean
Function
Object
Null
Undefined
6. What boolean operators does JavaScript support?
&&, || and !
7. What is negative infinity?
It’s a number in JavaScript, derived by dividing negative number by zero.
8. Is it possible to check if a variable is an object?
Yes, it is possible to do so. The following piece of code will help achieve the same.
if(abc && typeof abc === "object") {
console.log('abc is an object and does not return null value');
}
console.log('abc is an object and does not return null value');
}
9. Can you explain what isNaN function does?
isNaN function will check an argument and return TRUE (1) if the argument does not seem to be a number.
10. How do you convert numbers between different bases in JavaScript?
Use the
parseInt() function, that takes a string as the first parameter, and the
base as a second parameter. So to convert hexadecimal 3F to decimal,
use parseInt ("3F", 16);
11. What is the difference between undefined value and null value?
undefined means
a variable has been declared but has not yet been assigned a value. On
the other hand, null is an assignment value. It can be assigned to a
variable as a representation of no value.
Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
Unassigned variables are initialized by JavaScript with a default value
of undefined. JavaScript never sets a value to null. That must be done
programmatically.
12. What is the difference between “==” and “===”?
While “==” checks only for equality, “===” checks for equality as well as the type.
13. Differentiate between “var a=2” and “a =2”
The major
difference between the two is that one variable is local and the other
is global. “var” basically defines the scope of the variable.
When we add var
to a variable value assignment, javascript ensures that the variable is
confined to whichever function it is assigned to and does not collide
with the same name variable within another function.
When we don’t
use var, then it is declared as a global function and chances of
collision can happen. So it’s always advisable to use “var” before
variable value assignment. If needed use an anonymous function for
closure.
14. What is Javascript namespacing? How and where is it used?
Using global
variables in Javascript is evil and a bad practice. That being said,
namespacing is used to bundle up all your functionality using a unique
name. In JavaScript, a namespace is really just an object that you’ve
attached all further methods, properties and objects. It promotes
modularity and code reuse in the application.
15. What does "1"+2+4 evaluate to?
Since 1 is a string, everything is a string, so the result is 124.
16. How about 2+5+"8"?
Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.
17. How to create arrays in JavaScript?
We can declare an array like this
var scripts = new Array();
We can add elements to this array like this
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
Now our array
scrips has 4 elements inside it and we can print or access them by using
their index number. Note that index number starts from 0. To get the
third element of the array we have to use the index number 2 . Here is
the way to get the third element of an array.
document.write(scripts[2]);
We also can create an array like this
var no_array = new Array(21, 22, 23, 24, 25);
document.write(scripts[2]);
We also can create an array like this
var no_array = new Array(21, 22, 23, 24, 25);
18. How do you create a new object in JavaScript?
var obj = new Object(); or var obj = {};
19. How do you assign object properties?
obj["age"] = 17 or obj.age = 17
20. What’s a way to append a value to an array?
arr[arr.length] = value;
21. What is this keyword?
It refers to the current object.
22. How many looping structures can you find in javascript?
If you are a
programmer, you know the use of loops. It is used to run a piece of code
multiple times according to some particular condition. Javascript being
a popular scripting language supports the following loops
for
while
do-while loop
while
do-while loop
23. Are javascript and jQuery different?
jQuery is a
quick as well as concise JavaScript Library that simplifies HTML
document traversing, animating, event handling, & Ajax interactions
for the purpose of quick web development needs. So although they are not
entirely different, both are not the same either!
24. Explain the strict mode in Javascript.
The strict mode
ensures that if functions are not properly thought it, those are
disabled. It also kept a check on potentially unsafe actions and throw
errors when it happens.
25. Is it possible for you to write a one line JavaScript code that concatenates all strings passed into a function?
The following function should help in producing the desired result
function concatenate()
{
return String.prototype.concat.apply('', arguments);
}
{
return String.prototype.concat.apply('', arguments);
}
26. Explain Javascript closures.
A basic overview of javascript closures is that it is a stack-frame which is not de-allocated when the function returns.
27. What is event bubbling?
Event bubbling
describes the behavior of events in child and parent nodes in the
Document Object Model (DOM); that is, all child node events are
automatically passed to its parent nodes. The benefit of this method is
speed, because the code only needs to traverse the DOM tree once. This
is useful when you want to place more than one event listener on a DOM
element since you can put just one listener on all of the elements, thus
code simplicity and reduction. One application of this is the creation
of one event listener on a page’s body element to respond to any click
event that occurs within the page’s body.
28. Difference between window.onload and onDocumentReady?
The onload
event does not fire until every last piece of the page is loaded, this
includes css and images, which means there’s a huge delay before any
code is executed.
That isnt what we want. We just want to wait until the DOM is loaded and is able to be manipulated. onDocumentReady allows the programmer to do that.
29. How do you change the style/class on any element?
document.getElementById(“myText”).style.fontSize = “20″;
-or-
document.getElementById(“myText”).className = “anyclass”;
-or-
document.getElementById(“myText”).className = “anyclass”;
30. How is form submission possible via javascript?
We can achieve the desired form submission by using the function document.forms[0].submit().
It must be
noted that the 0 in the piece of code given above refers to the form
index. Say we have multiple forms on a particular page. To make all the
form procession unique, we give each form index numbers. The first form
will have the index number as 0. The second form will have an
incremented number, 1. The third will have 2 and so on.
31. How JavaScript timers work? What is a drawback of JavaScript timers?
Timers allow
you to execute code at a set time or repeatedly using an interval. This
is accomplished with the setTimeout, setInterval, and clearInterval
functions. The setTimeout(function, delay) function initiates a timer
that calls a specific function after the delay; it returns an id value
that can be used to access it later. The setInterval(function, delay)
function is similar to the setTimeout function except that it executes
repeatedly on the delay and only stops when cancelled. The
clearInterval(id) function is used to stop a timer. Timers can be tricky
to use since they operate within a single thread, thus events queue up
waiting to execute.
32. How to get CheckBox status whether it is checked or not?
alert(document.getElementById('checkbox1').checked);
if it will be checked you will get true else false.
33. How to get value from a textbox?
alert(document.getElementById('txtbox1').value);
34. How to get value from dropdown (select) control?
alert(document.getElementById('dropdown1').value);
35. How to get value from RadioButtonList control?
Here id is the name property of the RadioButtonList
function GetRadioButtonValue(id)
{
var radio = document.getElementsByName(id);
for (var ii = 0; ii < radio.length; ii++)
{
if (radio[ii].checked)
alert(radio[ii].value);
}
}
36. How to detect the operating system on the client machine?
In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used......
Wednesday, 29 January 2014
Php Interview Question Answer
Q-What is PHP?
A- PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for web development. PHP scripts are executed on the server.PHP allows writing dynamically generated web pages efficiently and quickly. The syntax is mostly borrowed from C, Java and perl. PHP is free to download and
use.
Q-Explain the different types of errors in PHP.
A- Notices, Warnings and Fatal errors are the types of errors in PHP
Notices: -
Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.
Warnings: -
Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.
Fatal errors: -
Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.
Q-What is difference between require_once(), require(), include()?
A- require() includes and evaluates a specific file, if the file is not found then it shows a Fatal Error.
require_once() includes only the file which is not being included before. It is used to be recommended for the files where you have lots of functions stored.
include() includes the file, even if the file is not found, but it gives a warning to the user to include().
Q- Write a program to show the joining of two strings in PHP?
A- Two strings can be joined together by the use of a process called as concatenation. A dot (.) operator is used for this purpose. Example is as follows:
$string1 = _Hello_;
$string2 = _World!_;
$stringall = $string1.$string2;
echo $stringall;
Q- Explain when to use GET or POST. Provide example for both the ways.
A- Both GET and POST are used to collect data from a form. However, when security is desired $_POST should be used. When the $_ POST variable is used, all variables used are NOT displayed in the URL. Also, they have no restrictions to the length of the variables. GET should be used when the interaction with the form is more like a question. For e.g. firing a query etc. POST should be used more often when the interaction is more like an order or the interaction changes the state of the resource.
POST example:
<form action="sample.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
On clicking submit the URL resembles to: http://www.mysamplesite.com/sample.php
The sample.php file can be used for catching the form data using $_POST
Hello <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!
GET EXAMPLE
<form action="sample.php" method="get">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
On clicking submit the URL resembles to : http://www.mysamplesite.com/sample.php?name=jim&age=37
The sample.php file can be used for catching the form data using $_GET
Hello <?php echo $_GET["name"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!
Q- What is HereDoc in PHP?
A- PHP heredoc syntax allows creating multiple lines of string without using quotations.
Example: Here, the heredoc starts with <<< operator and the multiple lines are followed. <<<identifier_name is used as an identifier making the start of heredoc. To end the heredoc, the identifier is written again.
<?php
$str = <<<Sample
This is a sample string
A sample string
Sample;
Echo $str;
?>
Q- what is Session ? how to Start a Session and Destroy ?
A- PHP sessions introduction
When a user logs in an application, his details are usually stored in a session variable. This information is available to all pages in one application. Sessions in PHP work using a unique id for each visitor.
Starting a php session: This tag must also appear before the HTML tag.
Session_start();
Storing a session variable: Here in the sample variable value is set to 1
Session_start();
$_session[‘sample]=1;
Destroying a session:
Session_destory();
Q- Is multiple inheritance supported in PHP?
A- PHP includes only single inheritance, it means that a class can be extended from only one single class using the keyword ‘extended’.
Q- What is the meaning of a final class and a final method?
Q- ‘final’ is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overrided.
Q- How is it possible to set an infinite execution time for PHP script?
A- The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded’.It is also possible to specify this in the php.ini file.
Q- What is the function file_get_contents() usefull for?
A- file_get_contents() lets reading a file and storing it in a string variable.
Q- How can we connect to a MySQL database from a PHP script?
A- To be able to connect to a MySQL database, we must use mysql_connect() function as follows:-
<?php
$database = mysql_connect("HOST", "USER_NAME", "PASSWORD");
mysql_select_db("DATABASE_NAME",$database);
?>
Q- What is the function mysql_pconnect() usefull for?
A- mysql_pconnect() ensure a persistent connection to the database, it means that the connection do not close when the the PHP script ends.
Q- How is it possible to know the number of rows returned in result set?
A- The function mysql_num_rows() returns the number of rows in a result set.
Q- What is the difference between mysql_fetch_object() and mysql_fetch_array()?
A- The mysql_fetch_object() function collects the first single matching record where mysql_fetch_array() collects all matching records from the table in an array.
Q- How can we check the value of a given variable is a number?
A- It is possible to use the dedicated function, is_numeric() to check whether it is a number or not.
Q- How can we check the value of a given variable is a number?
A- It is possible to use the dedicated function, is_numeric() to check whether it is a number or not.
http://dense13.com/blog/2008/
A- PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for web development. PHP scripts are executed on the server.PHP allows writing dynamically generated web pages efficiently and quickly. The syntax is mostly borrowed from C, Java and perl. PHP is free to download and
use.
Q-Explain the different types of errors in PHP.
A- Notices, Warnings and Fatal errors are the types of errors in PHP
Notices: -
Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.
Warnings: -
Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.
Fatal errors: -
Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.
Q-What is difference between require_once(), require(), include()?
A- require() includes and evaluates a specific file, if the file is not found then it shows a Fatal Error.
require_once() includes only the file which is not being included before. It is used to be recommended for the files where you have lots of functions stored.
include() includes the file, even if the file is not found, but it gives a warning to the user to include().
Q- Write a program to show the joining of two strings in PHP?
A- Two strings can be joined together by the use of a process called as concatenation. A dot (.) operator is used for this purpose. Example is as follows:
$string1 = _Hello_;
$string2 = _World!_;
$stringall = $string1.$string2;
echo $stringall;
Q- Explain when to use GET or POST. Provide example for both the ways.
A- Both GET and POST are used to collect data from a form. However, when security is desired $_POST should be used. When the $_ POST variable is used, all variables used are NOT displayed in the URL. Also, they have no restrictions to the length of the variables. GET should be used when the interaction with the form is more like a question. For e.g. firing a query etc. POST should be used more often when the interaction is more like an order or the interaction changes the state of the resource.
POST example:
<form action="sample.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
On clicking submit the URL resembles to: http://www.mysamplesite.com/sample.php
The sample.php file can be used for catching the form data using $_POST
Hello <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!
GET EXAMPLE
<form action="sample.php" method="get">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
On clicking submit the URL resembles to : http://www.mysamplesite.com/sample.php?name=jim&age=37
The sample.php file can be used for catching the form data using $_GET
Hello <?php echo $_GET["name"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!
Q- What is HereDoc in PHP?
A- PHP heredoc syntax allows creating multiple lines of string without using quotations.
Example: Here, the heredoc starts with <<< operator and the multiple lines are followed. <<<identifier_name is used as an identifier making the start of heredoc. To end the heredoc, the identifier is written again.
<?php
$str = <<<Sample
This is a sample string
A sample string
Sample;
Echo $str;
?>
Q- what is Session ? how to Start a Session and Destroy ?
A- PHP sessions introduction
When a user logs in an application, his details are usually stored in a session variable. This information is available to all pages in one application. Sessions in PHP work using a unique id for each visitor.
Starting a php session: This tag must also appear before the HTML tag.
Session_start();
Storing a session variable: Here in the sample variable value is set to 1
Session_start();
$_session[‘sample]=1;
Destroying a session:
Session_destory();
Q- Is multiple inheritance supported in PHP?
A- PHP includes only single inheritance, it means that a class can be extended from only one single class using the keyword ‘extended’.
Q- What is the meaning of a final class and a final method?
Q- ‘final’ is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overrided.
Q- How is it possible to set an infinite execution time for PHP script?
A- The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded’.It is also possible to specify this in the php.ini file.
Q- What is the function file_get_contents() usefull for?
A- file_get_contents() lets reading a file and storing it in a string variable.
Q- How can we connect to a MySQL database from a PHP script?
A- To be able to connect to a MySQL database, we must use mysql_connect() function as follows:-
<?php
$database = mysql_connect("HOST", "USER_NAME", "PASSWORD");
mysql_select_db("DATABASE_NAME",$database);
?>
Q- What is the function mysql_pconnect() usefull for?
A- mysql_pconnect() ensure a persistent connection to the database, it means that the connection do not close when the the PHP script ends.
Q- How is it possible to know the number of rows returned in result set?
A- The function mysql_num_rows() returns the number of rows in a result set.
Q- What is the difference between mysql_fetch_object() and mysql_fetch_array()?
A- The mysql_fetch_object() function collects the first single matching record where mysql_fetch_array() collects all matching records from the table in an array.
Q- How can we check the value of a given variable is a number?
A- It is possible to use the dedicated function, is_numeric() to check whether it is a number or not.
Q- How can we check the value of a given variable is a number?
A- It is possible to use the dedicated function, is_numeric() to check whether it is a number or not.
Q- Add www before url through .htaccess file.
Ans- Check this link -
http://dense13.com/blog/2008/ 02/27/redirecting-non-www-to- www-with-htaccess/
Php interview question answer
| Q:1 | What are the differences between Get and post methods in form submitting. give the case where we can use get and we can use post methods? |
| A:1 | When to use GET or POST
The HTML 2.0 specification says, in section Form
Submission (and the HTML 4.0 specification repeats this with minor stylistic changes):
–>If the processing of a form is idempotent
(i.e. it has no lasting observable effect on the state of the world), then the form method should be GET. Many database searches have no visible side-effects and make ideal applications of query forms. – –>If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST. How the form data is transmitted?
quotation from the HTML 4.0 specification
–> If the method is “get” – -, the user agent
takes the value of action, appends a ? to it, then appends the form data set, encoded using the application/x-www-form-urlencoded content type. The user agent then traverses the link to this URI. In this scenario, form data are restricted to ASCII codes. –> If the method is “post” –, the user agent conducts an HTTP post transaction using the value of the action attribute and a message created according to the content type specified by the enctype attribute. Quote from CGI FAQ
Firstly, the the HTTP protocol specifies
differing usages for the two methods. GET requests should always be idempotent on the server. This means that whereas one GET request might (rarely) change some state on the Server, two or more identical requests will have no further effect.
This is a theoretical point which is also good
advice in practice. If a user hits “reload” on his/her browser, an identical request will be sent to the server, potentially resulting in two identical database or guestbook entries, counter increments, etc. Browsers may reload a GET URL automatically, particularly if cacheing is disabled (as is usually the case with CGI output), but will typically prompt the user before re-submitting a POST request. This means you’re far less likely to get inadvertently-repeated entries from POST.
GET is (in theory) the preferred method for
idempotent operations, such as querying a database, though it matters little if you’re using a form. There is a further practical constraint that many systems have built-in limits to the length of a GET request they can handle: when the total size of a request (URL+params) approaches or exceeds 1Kb, you are well-advised to use POST in any case.
I would prefer POST when I don’t want the status to
be change when user resubmits. And GET when it does not matter. |
| Q:2 | Who is the father of PHP and explain the changes in PHP versions? |
| A:2 | Rasmus Lerdorf is known as the father of PHP.PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3 is the successor to PHP/FI 2.0 and is a lot nicer. PHP 4 is the current generation of PHP, which uses the Zend engine under the hood. PHP 5 uses Zend engine 2 which, among other things, offers many additionalOOP features |
| Q:3 | How can we submit a form without a submit button? |
| A:3 | The main idea behind this is to use Java script submit() function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit() method to onclick, onchange events of different inputs and perform the form submission. you can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites). |
| Q:4 | In how many ways we can retrieve the data in the result set of MySQL using PHP? |
| A:4 | You can do it by 4 Ways1. mysql_fetch_row. 2. mysql_fetch_array 3. mysql_fetch_object 4. mysql_fetch_assoc |
| Q:5 | What is the difference between mysql_fetch_object and mysql_fetch_array? |
| A:5 | mysql_fetch_object() is similar tomysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names). |
| Q:6 | What is the difference between $message and $$message? |
| A:6 | It is a classic example of PHP’s variable variables. take the following example.$message = “Mizan”;$$message = “is a moderator of PHPXperts.”;$message is a simple PHP variable that we are used to. But the $$message is not a very familiar face. It creates a variable name $mizan with the value “is a moderator of PHPXperts.” assigned. break it like this${$message} => $mizanSometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically. |
| Q:7 | How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’ using regular expression of PHP? |
| A:7 | preg_match(“/^http:\/\/.+@(.+)$/”,’http://info@abc.com’,$found); echo $found[1]; |
| Q:8 | How can we create a database using PHP and MySQL? |
| A:8 | We can create MySQL database with the use of mysql_create_db(“Database Name”) |
| Q:9 | What are the differences between require and include, include_once and require_once? |
| A:9 |
The include() statement includes
and evaluates the specified file.The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.
The include_once()
require_once()statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. As the name suggests, it will be included just once.include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. |
| Q:10 | Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”? |
| A:10 | Yes we can use include() more than one time in any page though it is not a very good practice. |
| Q:11 | What are the different tables present in MySQL, which type of table is generated when we are creating a table in the following syntax: create table employee (eno int(2),ename varchar(10)) ? |
| A:11 | Total 5 types of tables we can create 1. MyISAM 2. Heap 3. Merge 4. INNO DB 5. ISAM MyISAM is the default storage engine as of MySQL 3.23 and as a result if we do not specify the table name explicitly it will be assigned to the default engine. |
| Q:12 | Functions in IMAP, POP3 AND LDAP? |
| A:12 | You can find these specific information in PHP Manual. |
| Q:13 | How can I execute a PHP script using command line? |
| A:13 | As of version 4.3.0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface. Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program. Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment. |
| Q:14 | Suppose your Zend engine supports the mode <? ?> Then how can u configure your PHP Zend engine to support <?PHP ?> mode ? |
| A:14 | In php.ini file: set short_open_tag=on to make PHP support |
| Q:15 | Shopping cart online validation i.e. how can we configure Paypal, etc.? |
| A:15 | We can find the detail documentation about different paypal integration process at the following site |
Subscribe to:
Posts (Atom)