Introduction to PHP FdSc Module 109 Server side scripting and Database design 2014
Client server architecture http://www.webdevelopersnotes.com/basics/client_server_architecture.php3
Client server architecture Client server computing is: an environment which satisfies a business need by appropriately allocating the application processing between the client and server processors A client provides presentation services, computing power and connectivity A server provides computing, connectivity and database services
Client server architecture The protocol is that the Client requests a service from the server The server processes the request and returns the results to the client A server can service many clients at the same time and regulate their access to shared resources A server can reside on the same machine as the client, or on a different machine across a network
Client server architecture Ideal client server software is independent of hardware or operating systems Client server is scalable Extra clients can be added or removed with only slight performance impacts Servers can be migrated to bigger or multiple machines
Client server architecture Server code and data are centrally managed Cheaper maintenance Data integrity Secure access
Benefits Data is available to all authorised users Structured Query Language (SQL) allows access from all client processors and software Applications can be developed without regard to hardware platforms or technical characteristics of the software Systems using SQL are transparent to data storage location and technology
Benefits Applications can have a consistent look and feel Servers can be repaired, replaced, upgraded or relocated without the client being aware
Database software Comparison of industrial databases (and Access) Product Maximum Size Maximum Table size Maximum row size Maximum fields per row IBM DB2 512 TB 32 kB 1012 MS SQL 524 TB Unlimited 30k MySQL 265 TB 64 kB 4096 Oracle 4GB 8 kB 1000 MS Access 2 GB 16 MB 255
Server components http://www.frogcp.com/php-hosting-with-mysql
Components of a client server web based application Database and server Returns data when requested by SQL We will use MySQL Web server Serves web pages in HTML We use Apache Server side PHP interpreter Substitutes HTML for PHP scripts which can issue SQL and return data Client Your web browser of choice
College set up Each student has For home you can use XAMPP A folder for storing the web site MySQL PHP FTP access Apache For home you can use XAMPP
Tools Contextual editors FTP MySQL Notepad++ (Windows) GEDIT (Linux) PHPStorm IDE FTP Filezilla MySQL PHPMyAdmin
What is PHP? A server side language Scripts that allow you to control the content of web pages Unlike Javascript in the browser, which does the same job, PHP runs on the web server PHP scripts are embedded in HTML pages When the page is served, the PHP interpreter replaces the PHP with HTML, based on what the script tells it to do
Example XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xm<!DOCTYPE html PUBLIC "-//W3C//DTD lns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Today’s Date</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <p>Today’s date (according to this web server) is <?php echo date('l, F dS Y.'); ?> </p> </body> </html>
What the browser shows Today’s date (according to this web server) is Saturday, January 28th 2012. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Today’s Date</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <p>Today’s date (according to this web server) is Saturday, January 28th 2012. </p> </body> </html>
Advantages No browser incompatibility issues Browser only receives HTML Access to server side resources Databases Reduced load on client Java can significantly slow down browsers
Practicalities – method 1 Use an FTP client (I use Filezilla) to create a subdirectory on your student account Host is hosting.computing.hct.ac.uk User is your hosting: username Password is your hosting: password The web site is: hosting.computing.hct.ac.uk/username Use a contextual editor (Notepad++ or gedit to create the file we just used and save it with a file type of .php (I called it test1.php) in the subdirectory Access it using your browser Make sure it works
Practicalities – method 2 PHPStorm – connections Select Settings from the File menu Select Deployment
PHPStorm - connections Use these settings, replacing BDOCMS with your username Then select Advanced Options
PHPStorm - connections In advanced options select Passive Mode
PHPStorm - connections Select the Mappings tab and set up the local storage Test the connection then click OK
PHPStorm usage PHPStorm has a contextual editor working on local files and will automatically synch up to the host.