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.
No comments:
Post a Comment