Web Database
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)
);