Web Dbs & PHP
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
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.
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.”
•
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
•Click Download
•Execute setup.exe
• 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)
•Download from
http://dev.mysql.com/downloads/other/mysqlcc
.html
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.
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:
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