Professional Documents
Culture Documents
Assignment PDF
Assignment PDF
1
Question.2 Write a program to Connect Database already created in MySQL.
Program:-
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
<?php
function writeMsg() {
echo "Hello world!";
}
2
Question.4 Explain various MySQL Data Types?
Answers:- MySQL Data Types are of three types they are:-
3
Date and Time Data Type:
4
Question.5 Write Short Note on following. (any 4)
Answers:-
Static webpages and Dynamic webpages
Static Web pages:
Static Web pages are very simple. It is written in languages such as HTML, JavaScript, CSS, etc.
For static web pages when a server receives a request for a web page, then the server sends the
response to the client without doing any additional process. And these web pages are seen
through a web browser. In static web pages, Pages will remain the same until someone changes it
manually.
Dynamic Web Pages:
Dynamic Web Pages are written in languages such as CGI, AJAX, ASP, ASP.NET, etc. In
dynamic web pages, the Content of pages is different for different visitors. It takes more time to
load than the static web page. Dynamic web pages are used where the information is changed
frequently, for example, stock prices, weather information, etc.
Difference between Static and Dynamic Web Pages:
S.No Static Web Pages Dynamic Web Pages
Static Web Page takes less time for Dynamic web page takes more time
4. loading than dynamic web page. for loading.
Static web pages are written in Dynamic web pages are written in
languages such as: HTML, languages such as: CGI, AJAX, ASP,
6. JavaScript, CSS, etc. ASP.NET, etc.
5
CSS
CSS stands for Cascading Style Sheets. It is a style sheet language which is used to describe the
look and formatting of a document written in markup language. It provides an additional feature
to HTML. It is generally used with HTML to change the style of web pages and user interfaces.
It can also be used with any kind of XML documents including plain XML, SVG and XUL.
CSS is used along with HTML and JavaScript in most websites to create user interfaces for web
applications and user interfaces for many mobile applications.
These are the three major benefits of CSS:
Solves a big problem
Saves a lot of time
Provide more attributes
CSS Syntax as follows −
Selector − A selector is an HTML tag at which a style will be applied. This could be any
tag like <h1> or <table> etc.
Property − A property is a type of attribute of HTML tag. Put simply, all the HTML
attributes are converted into CSS properties. They could be color, border etc.
Value − Values are assigned to properties. For example, color property can have value
either red or #F1F1F1 etc.
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
text-align: center;
}
</style>
</head>
<body>
<p>Hello World!</p>
<p>These paragraphs are styled with CSS.</p>
</body>
</html>
6
Loops:-
When you write code, you want the same block of code to run over and over again a certain
number of times. So, instead of adding several almost equal code-lines in a script, we can use
loops.
Loops are used to execute the same block of code again and again, as long as a certain condition
is true.
In PHP, we have the following loop types:
while - loops through a block of code as long as the specified condition is true
do...while - loops through a block of code once, and then repeats the loop as long as the
specified condition is true
for - loops through a block of code a specified number of times
foreach - loops through a block of code for each element in an array
While Loop
The while loop executes a block of code as long as the specified condition is true.
Syntax
Examples
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
Do...while Loop
The do...while loop will always execute the block of code once, it will then check the condition,
and repeat the loop while the specified condition is true.
7
Examples
<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
For Loop
The For loop is used when you know in advance how many times the script should run.
Syntax
Examples
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
Form in PHP
<html>
<body>
</body>
</html>
8
Question.6 Different Between MySQL and MySQLi.
Answers:-
MySQL MySQLi
MySQL extension added in PHP version 2.0. MySQLi extension added in PHP 5.5 and
and deprecated as of PHP 5.5.0. will work on MySQL 4.1.3 or above.
MySQL provides the procedural interface. MySQLi provides both procedural and
object-oriented interface.
MySQL extension does not support stored MySQLi supports store procedure.
procedure.
MySQL extension lags in security and other MySQLi extension is with enhanced
special features, comparatively. security and improved debugging.
Transactions are handled by SQL queries only. MySQLi supports transactions through API.
9
Question.7 Write a PHP Program which create a login page by using POST method.
Program:-
<html>
<head>
<title>My First PHP Program!</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<p>username <input type="text" name="usser"/></p>
<p>password <input type="password" name="pass" /></p>
<p> <input type="submit" name="submit" /></p>
</form>
<?php
$name = $_REQUEST['usser'];
$pas=$_REQUEST['pass'];
if($name=="mandeep"&&$pas=="mani"){
echo "successful";
}
else{
echo "Login Failed";
}
?>
</body>
</html>
10
Manipulating String:-
strlen() - Return the Length of a String. The PHP strlen() function returns the length of a
string.
Example
Return the length of the string "Hello world!":
<?php
echo strlen("Hello world!"); // outputs 12
?>
<?php
echo str_word_count("Hello world!"); // outputs 2
?>
<?php
echo strrev("Hello world!"); // outputs !dlrow olleH
?>
11
Question.9 Explain following MySQL command.
Answers:-
SELECT Statement
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT Syntax
Here, column1, column2, ... are the field names of the table you want to select data from. If you
want to select all the fields available in the table, use the following syntax:
WHERE Statement
We have seen the SQL SELECT command to fetch data from a MySQL table. We can use a
conditional clause called the WHERE Clause to filter out the results. Using this WHERE
clause, we can specify a selection criteria to select the required records from a table.
Syntax
The following code block has a generic SQL syntax of the SELECT command with the WHERE
clause to fetch data from the MySQL table −
INSERT Statement
To insert data into a MySQL table, you would need to use the SQL INSERT INTO command.
You can insert data into the MySQL table by using the mysql> prompt or by using any script like
PHP.
Syntax
Here is a generic SQL syntax of INSERT INTO command to insert data into the MySQL table −
12
To insert string data types, it is required to keep all the values into double or single quotes. For
example "value".
DELETE Statement
If you want to delete a record from any MySQL table, then you can use the SQL
command DELETE FROM. You can use this command at the mysql> prompt as well as in any
script like PHP.
Syntax
The following code block has a generic SQL syntax of the DELETE command to delete data
from a MySQL table.
If the WHERE clause is not specified, then all the records will be deleted from the given
MySQL table.
You can specify any condition using the WHERE clause.
You can delete records in a single table at a time.
The WHERE clause is very useful when you want to delete selected rows in a table.
13