0% found this document useful (0 votes)
167 views42 pages

Web Dbs & PHP

Uploaded by

kihadha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views42 pages

Web Dbs & PHP

Uploaded by

kihadha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 42

Web DBs & PHP

Topics Covered
•Database Driven Web
•Open Source Software
(LAMP - Linux, Apache, MySQL and PHP)

•References
Database Driven Web Application
•A database web application is an application based on World
Wide Web (Internet) and database using web browser as a
client.
•Traditional client-server (2-tier architecture): A client
computer handles the user interface (Access Forms, Oracle
Forms, Reports) and a database server stores the data. The
actual functionality (business logic) of the application resides
on the client and/or in the databases
•Web-based (multi-tier architecture): A client computer
uses a browser to access information from two or more
servers (web servers, application servers, database servers)
(i.e.) A web server handles web requests, an application
server handles dynamic requests and a database server
stores the data)
Application
Clients Database Server
Servers including
web servers
Three-Tier Architecture
Benefits of Web Applications

•Free Infrastructure: A major benefit is that the whole


infrastructure is already in place and well developed. Only a web
browser is needed. The new applications can be available to all
the relevant users immediately – IT support staff do not have to go
to each client workstation to install the Client Software

• Free Upgrades: As the application resides on the server, new


versions will be immediately and simultaneously available to every
user. There is no need to distribute updated application files to
every user.

•Interchangeable components: It is possible to exchange either


the server or the browser without breaking the application.
Web Technologies
Client-side
•HTML (Hyper Text Markup Language)
•CSS (Cascading Style Sheets)
•XML (Extensible Markup Language)
•DTD (Document Type Declaration)
•XSLT (Extensible Style Sheet Language Translator)
•JavaScript
•VBScript/Jscript
•Animation (Flash )
•Dynamic Hypertext Markup Language (DHTML –
HTML, JavaScript, CSS & Document Object Model
(DOM)
Web Technologies
Server-side
o PHP
o ASP (Active Server Pages) & ASP.NET
o JSP (Java Server Pages)
o Java Servlets
o C++/Java
o PERL
o XML
Database
 ODBC
7
 JDBC 10/22/10
 OleDB
CGI (Common Gateway Interface)
• Set of rules that define how web server
communicates with other software on the
same machine
• Defines how the other software (CGI program)
talks back to the web server
• Has nothing to do with any particular
programming language!
• Often confused with Perl
CGI … what can it do?
Can dynamically create web content
• – Reacting from user input or other factors

For example:
• – User inputs data into form
• – Posts it to web server
• – CGI program
• 1.receives data
• 2.processes it
• 3.and returns tailored page to web server for user
9 10/22/10
CGI today
Still used
• – Widely supported
• – Established standard
• – Portable
• – Can return any content supported by server (not just HTML)
But
• – Needs a programmer – Perl, C, C++, TCL, BASIC
• – Can be fiddly to debug
• – Has been known to cause security problems
• – CGI Overhead
• Fork off new process
• Initialise scripts
• Server implementation specific issues!
10 10/22/10
SSI (Server Side Includes)
Innovation of NCSA's HTTPD
• And non-standard
• Simple interface for creating dynamic content
• If your application doesn’t need an executable
perhaps consider SSI
– i.e. including a navigation bar on all pages or
“house styles”
• – Can only return an HTML page
ASP (Active Server Pages)
Microsoft’s server-side offering
• – Runs on MS web servers (IIS or PWS)
• – Latest ASP.NET
You write HTML pages with little bits of Visual
• Basic or C# embedded in between <% %> tags
• Server interprets them before delivering the
page
Example:
<H1>Today is:</H1> <%= System.DateTime.Now.ToString()
%>
JSP (Java Server Pages)
• Sun Microsystems equivalent of ASP
• Based on Java technology
• You write HTML with little bits of Java
embedded in between <% %> tags
• Server interprets them before delivering the
page
• It compiles them into Servlets (see later)
Example:
<H1>Today is:</H1> <%= new java.util.Date() %>
ASP VS JSP
• Both simple fast methods of creating dynamic web
content
– As compared to CGI
• JSP is an industry wide initiative led by Sun
• ASP is Microsoft
• – Portability issues?
– “Apache has roughly 70% share in web server market
– & supports JSP via Jakarta Tomcat”
– So Microsoft got together with Covalent technologies and got
ASP.NET onto Apache
• JSP can run on NT and IIS web servers through third
party solutions
Open Source Software
• www.opensource.org
• Software in a community that is:
– Freely Used (no warranty, no limits on usage)
– Source code is available for any modifications
– Freely Extended (must share source, represent original
works and owners)
– License is not specific to a product or restrict other software
and also technology neutral.

• There's always plenty of professional and peer


support from documentation and mailing lists.
• Runs on any Platform. Bugs are fixed rapidly, and
requests for features are always heard, evaluated,
and if feasible, implemented.
LAMP
Linux (www.linux.com)
– *nix flavour that is all the rage at the moment.
– Similar to Unix but free and runs on just about anything.
– Latest version: 9.2

Free
•Coordinated
Apache (www.apache.org) •Cross-platform
– Most popular web page serving software •Plenty of support
– Latest version: 2.0 •http://www.lamphost.net/

MySQL (www.mysql.com)
– Open source SQL database that is free and extremely powerful
– Latest version: 4.1 (though 5.0.1 is testing version)

PHP (www.php.net)
– PHP (Hypertext Preprocessor) is mainly focused on server-side
scripting, so you can do anything any other CGI program can do, such as
collect form data, generate dynamic page content, or send and receive
cookies. But PHP can do much more.
– Latest version: 4.3 (though 5 is testing)
Software Usage
AMP
• One of the most powerful development models
for the Web has been the notion of “AMP.”

• AMP stands for “Apache / MySQL / PHP &


Perl working together.”
Apache is the MySQL is a very PHP / Perl is a
industry-leading popular general purpose
web server that database that scripting
runs a majority runs on most environment
of web servers operating widely used for
on the Internet. systems. building dynamic
web sites.
Together, they form the nucleus of a web application system.
www.easyphp.org -> contains the software needed for all three packages. You
can install and configure very easily. I am showing the installation separately
Apache, MySQL and PHP (AMP)
Integration
User

Us
er
Apache - Benefits
•Apache is well supported - Most support for Apache is free and
available 24 hours a day via Internet mail or newsgroups.
•Apache is multi-platform - Apache can run on virtually any hardware
platform (from PCs to mainframes), and almost any operating system,
such as Linux, Windows, NetWare, Macintosh, xBSD, etc.
•Apache is secure - security holes are rare but when they exist they
are discovered and fixed quickly
•Apache is extensible - anyone can write modules that easily plug in to
Apache. If Apache doesn't do what you want or need it to do, anyone
with programming skills can write the modules you need.
•Apache is database-friendly - you can interface Apache with virtually
any commercial database, such as Oracle, Sybase, DB2, and Informix,
as well as free databases such as MySQL and Postgres.
•Apache is hardware-friendly - Apache generally consumes far fewer
hardware resources that commercial web servers.
•No Microsoft Viruses - Apache is immune to the Code Red, Nimda,
and20other viruses that target at Microsoft
10/22/10 Web servers.
Installation – Apache (ver 2.0.52)
•Go to http://httpd.apache.org/download.cgi

• If you are downloading the Win32 distribution,


please read these important notes at the website
http://apache.mirror.mcgill.ca/httpd/binaries/win32/R
EADME.html

•Download the binary version

Win32 Binary (MSI Installer): apache_2.0.52-


win32-x86-no_ssl.msi
Installation – Apache (ver 2.0.52)
• Move to the folder where the
Apache is installed and double
click on the file to start the
installation.
• Welcome screen - Press Next
to continue
• Apache license – Accept the
terms and Press Next
• Brief intro – Read and Press
Next
• Server Information – Enter
admin user’s email
• Setup Type – Typical
• Destination Folder : leave to the
default and press Next
• Wait for installation to
complete
• You can change the settings in
httpd.conf file in conf folder
Starting Apache
• Find the port address
– Open httpd.conf and find the port number : 80, 8080 or
8088 (on this machine)  c:\program
files\Apachegroup\Apache2\conf folder
• Starting Apache service
– C:Program
Files\ApacheGroup\Apache2\bin\ApacheMonitor.exe. You
will see at the task bar
– Open the monitor and start the apache service if it is not
done already
• Testing the Apache web server
– http://localhost:8088/  You may have a different port
number
– you will see the test web page.
Configuration - Apache
• Edit and save httpd.conf file:
– Alter Options Indexes FollowSymLinks into
Options -Indexes FollowSymLinks

• Reboot Apache (not computer)


MySQL - Benefits
•In 1996 T.c.X. DataKonsultAB , a consulting firm in Sweden
developed MySQL.
•The largest growing relational database out on the market as it can
handle large databases that can be accessed over the Web - Meets
the ANSI SQL92 regulations (SQL-Structured Query Language)
•Mainly runs on UNIX-based environments, but also used on windows
•One of the most used open source databases in the world.
•Capacity to handle 50,000,000+ records.
•Very fast command execution, perhaps the fastest to be found on the
market.
•Flexible and secure password system to protect your data - powerful
security system
•Fast, reliable, easy to use, and affordable!
•On-line help facility - (type –help or -?,)
•Comes with a source code
•Multi-User and works on Several Platforms
Installation - MySQL
•Go to http://dev.mysql.com/downloads/mysql/5.0.html
and move to Windows (x86)5.0.0a-alpha26.7M

•Click Download

•Create folder called mysql and Unzip the file

•Execute setup.exe

•Welcome screen – Press Next to continue


•Information: Note down and press Next
•Destination Folder: Default (c:\mysql)
•Wait for installation to complete - Press Finish
Starting MySQL

• Go to C:\mysql\bin
• Execute winmysqladmin.exe. You will be prompted for
username and password. Type as admin with password as
admin
•You will see the Traffic light signal on the task bar and also
the admin window
Configuration - MySQL
MySQL Control Center
•Graphical administrative interface for MySQL
database(s)

•Can administer several DB servers that are


hosted on different machines

•Download from
http://dev.mysql.com/downloads/other/mysqlcc
.html

•Execute the file


MySQL Control Center - Configuration
 Open program in programs menu

 Establish connection
to DB server

10/22/10 30
MySQL Control Center - Configuration
 in Databases ignore mysql; delete test
 in User Administration delete
 first two users and assign
 password to root users
 ignore Server Administration
 adapt connection (password)

31 10/22/10
PHP Hypertext Preprocessor
Open-source technology
• Providing server-side scripting very similar to
ASP/JSP
• Source code and distribution freely available
• Large community of developers
• Implementations for
– All major UNIX, Linux and Windows operating
systems
– Accessing different databases
• especially MySQL but others inc Microsoft
Access

32 10/22/10
PHP
• A server-side embedded scripting language originally
created by Rasmus Lerdorf in 1994. PHP has changed
extensively since then.
• A PHP web page is a file containing HTML interspersed
with PHP script. the PHP script is executed on the server
and the resulting HTML sent to the client - very similar to
ASP.
• PHP syntax has much in common with Java, JavaScript,
Python and Perl. It is designed with the express intention
of making server scripting easy to code.
• PHP scripts can run as a
Common Gateway Interface (CGI) application
PHP… how?
Any web server
CGI is a standard across most web servers
High security
PHP runs in it's own process space so malicious
scripts cannot attack the server
...at least that was the idea
High reliability
A fault in the PHP does not affect the server
process
Can run as an Apache module
PHP can also run from the command line. This has
gained some popularity so the command line
interpreter is now built by default.
34 10/22/10
PHP as an Apache module?
High performance
the PHP interpreter runs as part of the
Apache process so no overhead of
spawning a new process
Persistent database connectivity
PHP does not stop running after servicing
the request
Vulnerable
Opens the possibility of attacking the server
process via a PHP script

35 10/22/10
PHP at UoG
• The Unix Apache webserver stuweb.cms.gre.ac.uk runs
5.0.5 and the Windoze IIS server cms-stu-iis.gre.ac.uk
runs 5.2.3 (the Windoze Apache server
stuapache.cms.gre.ac.uk is currently not working). Don't
be too surprised at differences between your domestic
installation and the University servers.

These notes are suitable for both PHP4 and PHP5.


Amongst other improvements PHP 5 provides an
improved implementation of DOM and we will use this
when we look more closely at XML.
Which OS?
• The natural home for PHP is a Unix/Linux platform runing Apache.

Windoze distributions are usually precompiled binaries, which is an


endorsement of one strength of the Win32 platform - there are only 4 major
versions to cope with and frequently a single software build can suit all four.

The configuration concepts are however pretty much the same for each
platform so regardless of the platform on which you are running there are a
couple of configuration files that it is a good idea to have a look at and
modify to suit your needs:

httpd.conf - the main apache config file


php.ini - the main PHP config file
PHP - Benefits
•Easy, powerful, popular
•Server-side scripting language
•Supports many DB’s (not only MySQL)
•Platform Independent
•Web Server Independent
•Free and Open Source
PHP Overtakes Microsoft ASP as the Web’s Number
1 server side Web technology for the Internet.
•An recent Netcraft surveys indicated 24 percent of
the 37.6 million websites, or are running PHP scripts.
PHP adoption is growing by 6.5 percent each month.
(9 million sites)
38 10/22/10
PHP & MySQL Books
1. PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide by Larry
Ullman, Peachpit Press, May 2003, ISBN 0-321-18648-6, 572 pages
2. Web Database Applications with PHP & MySQL by Hugh E. Williams & David
Lane O'Reilly & Associates, Mar 2002, ISBN 0-5960-0041-3, 582 pages
3. PHP MySQL Website Programming by Chris Lea, Mike Buzzard, Jessey White-
Cinis & Dilip Thomas Wrox Press Inc, Mar 2003, ISBN 1-861008-27-9, 500
pages
4. Sams Teach Yourself PHP, MySQL and Apache All in One By Julie Meloni,
SAMS, ISBN: 0672326205;
5. PHP Professional Projects by Ashish Wilfred, Meeta Gupta, Kartik Bhatnagar,
ISBN: 1-931841-53-5 © 2002
6. Beginnning PHP 5 and MySQL: From Novice to Professional by W. J. Gilmore
7. PHP and MySQL Web Development (3rd edition) by Luke Welling, Laura
Thomson

39 10/22/10
PHP References
•www.php.net <-- php home page
•http://www.phpbuilder.com/
•http://www.devshed.com/
•http://www.phpmyadmin.net/
•http://www.hotscripts.com/PHP/
•http://geocities.com/stuprojects/ChatroomDescription.htm
•http://www.academic.marist.edu/~kbhkj/chatroom/chatroom.htm
•http://www.aspfree.com/c/a/ASP-Code/Free-ASP-Based-Chat-
Program/
•http://www.aus-etrade.com/Scripts/php.php
•http://www.codeproject.com/asp/CDIChatSubmit.asp
•www.php.net/downloads <-- php downlad page
•http://www.php.net/manual/en/install.windows.php <-- php instllation
manual
•http://php.resourceindex.com/ <-- PHP resources like sample
programs, text book referencs, etc.
40 10/22/10
•http://www.daniweb.com/techtalkforums/forum17.html  php forums
MySQL References
• http://www.mysql.com/ - THE OFFICIAL MYSQL
WEBSITE
• http://www.mysql.com/documentation/ - CODING/HELP
DOCUMENTATION
• http://www.mysql.com/information/presentations/present
ation-ede2000-20001010/ - SYNTAX EXPLAINED
• http://hotwired.lycos.com/webmonkey/programming/php/
tutorials/tutorial4.html
PHP AND MYSQL TUTORIAL
• http://www.devshed.com/Server_Side/MySQL - THE
DEVELOPER SHED (MYSQL INFO.)
• http://www.faqts.com/knowledge_base/index.phtml/fid/94
MYSQL QUERIES AND COMMON PROBLEMS
• www.mysql.com
• http://www.freewebmasterhelp.com/tutorials/phpmysql
The end
Thank you for listenning

You might also like