0% found this document useful (0 votes)
20 views7 pages

Web Database

Database Management system for website design and software development tools and to store Database
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

Web Database

Database Management system for website design and software development tools and to store Database
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

WEB DATABASE

USING PHP
Prepared by Haftom
2009
Adigrat University
Introduction
■ Many electronic commerce (e-commerce) and other Internet applications that
provide Web interfaces to access information stored in one or more databases use
scripting languages. These languages are often used to generate HTML documents,
which are then displayed by the Web browser for interaction with the user.
■ Basic HTML is useful for generating static Web pages with fixed text and other
objects, but most ecommerce applications require Web pages that provide
interactive features with the user. For example, consider the case of an airline
customer who wants to check the arrival time and gate information of a particular
flight. The user may enter information such as a date and flight number in certain
form fields of the Web page
■ The Web program must first submit a query to the airline database to retrieve this
information, and then display it. Such Web pages, where part of the information is
extracted from databases or other data sources, are called dynamic Web pages.
The data extracted and displayed each time will be for different flights and dates.
■ There are various techniques for programming dynamic features into Web pages.
We will focus on one technique here, which is based on using the PHP open source
scripting language. PHP has recently experienced widespread use.
PHP
■ A PHP interpreter provides a Hypertext Preprocessor, which will execute PHP
commands in a text file and create the desired HTML file. To access
databases, a library of PHP functions needs to be included in the PHP
interpreter.
■ PHP programs are executed on the Web server computer. This is in contrast
to some scripting languages, such as JavaScript, that are executed on the
client computer.
■ PHP is an open source general-purpose scripting language. The interpreter
engine for PHP is written in the C programming language so it can be used
on nearly all types of computers and operating systems. PHP usually comes
installed with the UNIX operating system..
■ PHP is particularly suited for manipulation of text pages, and in particular for
manipulating dynamic HTML pages at the Web server computer.
■ PHP is ultimately text, taken by your web server and turned into a set of
commands and information for your web browser.
A Simple PHP example
<HTML>
<?php
phpinfo();
?>
</HTML>
Then test whether you have PHP installed properly. Type the following code
in a text editor and save it as test.php in a directory accessible by your
Web server:
<HTML>
<?php
echo "Hello World";
?>
</HTML>
You can tell that something is a variable in PHP because the name starts
with a $.
The web browser doesn’t actually run your program. Instead, it asks your
server to run the
program, and that server then gives the result of running sayHelloWeb.php
back to the browser, which shows you a personalized welcome message.
Your first database
Create database learndb;
Use learndb;
CREATE TABLE personnel
(
id int NOT NULL AUTO_INCREMENT,
firstname varchar(25),
lastname varchar(20),
nick varchar(12),
email varchar(35),
salary float(10,3),
PRIMARY KEY (id)

);

INSERT INTO personnel VALUES ('1','John','Lever','John', '[email protected]','75000');

INSERT INTO personnel VALUES ('2','Camilla','Anderson','Rose', '[email protected]','66000')


Where's my view? Viewdb.php
<HTML>
<?php
$db = mysql_connect("localhost", "root", ""); => it means connect to MySQL database
mysql_select_db("learndb",$db);
in localhost server with the username root and
$result = mysql_query("SELECT * FROM personnel",$db); in otherpassword
words, $db" points to our database server
echo "<TABLE>"; localhost. Next we select the database with which we
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Salary</B></TR>";want to interact with the lines
while ($myrow = mysql_fetch_array($result)) "mysql_select_db("learndb",$db);" which means we
{ We run wish toquery
this use the database
with the PHP"learndb"
commandlocated by the
mysql_query()
echo "<TR><TD>"; and save pointer
thevariable $db
result returned by the database to the
echo $myrow["firstname"]; variable $result
echo " "; We use the function mysql_fetch_array() to extract each
echo $myrow["lastname"]; row from $result and assign them to variable $myrow.
echo "<TD>";
So $myrow contains information about each row as
echo $myrow["nick"];
opposed to all the rows in $result.
echo "<TD>";
echo $myrow["salary"];
}
echo "</TABLE>";
?>
</HTML>
Creating HTML forms:
<HTML>
<BODY>
<form method="post" action="datain.php">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Nick Name:<input type="Text" name="nickname"><br>
E-mail:<input type="Text" name="email"><br>
Salary:<input type="Text" name="salary"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</HTML>

You might also like