PHP Exam Paper(part 1)
Answer Q2.
<?php
echo "<pre>";
$space = 10;
for ($i = 0; $i <= 10; $i++) {
for ($k = 0; $k < $space; $k++) {
echo " ";
}
for ($j = 0; $j < 2 * $i - 1; $j++) {
echo "*";
}
$space--;
echo "<br/>";
}
echo "</pre>";
?>
Answer Q2 B
coming soon............
1
2
3
4
5
(5+5+5)
Q1.shor notes (any three)
- variables
- $server
- Class
- require
(8+7)
Q2.
A). Write a script to print
*
* *
* * *
* * * *
* *
* * *
* * * *
B). Write a script to create a database with proper notification.
(8+7)
Q3.
A). What is file handling ? Explain any 5 attributes of file handling.
B). Write a program, to copy the content of a file into another file.
(8+7)
Q4.
A). Write difference between GET and POST.
B).Write a php script to get first name and last name from user and print it itno a new webpage.
(8+7)
Q5.
A). Write a PHP script to create a new table into a database.
B).Write a PHP scripte to insert a record into a table.
Answer:
Q1.A variable:
Variable is nothing it is just name of the memory location. A Variable is simply a container i.e used to store both numeric and non-numeric information.
Rules for Variable declaration
- Variables in PHP starts with a dollar($) sign, followed by the name of the variable.
- The variable name must begin with a letter or the underscore character.
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- A variable name should not contain space
Assigning Values to Variables
Assigning a value to a variable in PHP is quite east: use the equality(=) symbol, which also to the PHP's assignment operators.
This assign value on the right side of the equation to the variable on the left.
ex:
<?php
$myCar = "Honda";
echo $myCar;
?>
Answer Q1 B
$_SERVER :- $_SERVER is an array which holds information of headers, paths, script locations. Web server creates the entries in the array. This is not assured that every web server will provide similar information, rather some servers may include or exclude some information which are not listed here.
$_SERVER has following basic properties:
1. Set by web server.
2. Directly related to the runtime environment of the current php script.
3. It does the same job as $HTTP_SERVER_VARS used to do in previous versions of PHP
Answer Q1 B
$_SERVER :- $_SERVER is an array which holds information of headers, paths, script locations. Web server creates the entries in the array. This is not assured that every web server will provide similar information, rather some servers may include or exclude some information which are not listed here.
$_SERVER has following basic properties:
1. Set by web server.
2. Directly related to the runtime environment of the current php script.
3. It does the same job as $HTTP_SERVER_VARS used to do in previous versions of PHP
Answer Q1 D
The include() Function
The include() function takes all the text in a specified file and copies it into the file that uses the include function. If there is any problem in loading a file then the include() function generates a warning but the script will continue execution.
Assume you want to create a common menu for your website. Then create a file menu.php with the following content.
<a href="http://www.secretmind.cf/index.htm">Home</a> -
<a href="http://www.secretmind.cf/ebxml">ebXML</a> -
<a href="http://www.secretmind.cf/ajax">AJAX</a> -
<a href="http://www.secretmind.cf/perl">PERL</a> <br />
Now create as many pages as you like and include this file to create header. For example now your test.php file can have following content.
<html>
<body>
<?php include("menu.php"); ?>
<p>This is an example to show how to include PHP file!</p>
</body>
</html>
The include() function takes all the text in a specified file and copies it into the file that uses the include function. If there is any problem in loading a file then the include() function generates a warning but the script will continue execution.
Assume you want to create a common menu for your website. Then create a file menu.php with the following content.
<a href="http://www.secretmind.cf/index.htm">Home</a> -
<a href="http://www.secretmind.cf/ebxml">ebXML</a> -
<a href="http://www.secretmind.cf/ajax">AJAX</a> -
<a href="http://www.secretmind.cf/perl">PERL</a> <br />
Now create as many pages as you like and include this file to create header. For example now your test.php file can have following content.
<html>
<body>
<?php include("menu.php"); ?>
<p>This is an example to show how to include PHP file!</p>
</body>
</html>
Answer Q2.
<?php
echo "<pre>";
$space = 10;
for ($i = 0; $i <= 10; $i++) {
for ($k = 0; $k < $space; $k++) {
echo " ";
}
for ($j = 0; $j < 2 * $i - 1; $j++) {
echo "*";
}
$space--;
echo "<br/>";
}
echo "</pre>";
?>
Answer Q2 B
<?php
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
coming soon............
PHP Exam Paper(part 2)
(any four)
(8+7)
Q1.
A) Write difference between GET and POST.
B). What is loop ? Explain different types of loops use in php.
(8+7)
Q2.
A). write a script to print Fibonacci series from 20 to 95.
B). Write a script to check the given strings in palindrome or not (example: mom after reverse mom)
(8+7)
Q3
A) What is Array/ Explain the syntax with example.
B) what is file handling ? Write a program to show all the content of "result.txt" on console.
(8+7)
Q4
A). What is SQLs ?
B). Write a script to connect with the server and create a database name "studentdatabase".
(5+5+5)
Q5
A) write difference between.(any three)
- FTP and HTTP
- Array and variable
- Include and require
- echo and print
ليست هناك تعليقات:
إرسال تعليق
Please do not enter any spam link in the comment box.