SlideShare a Scribd company logo
Server-side Technology Dave Elliman
To Implement Megagamez’s Web Site: We need to build shopping trolley contents in a database We need to keep track of our customers and orders We will use MySQL and PHP to do this
Client-side and Server-side Scripting Client-side Javascript VBScript (MS) Can be used to validate input Can implement mouse-over effects etc Server-side cgi PHP ASP ASP.NET JSP Perl & Ruby – these ugly sisters will not be studied in ELC Communicates with database Application logic
Server Side Processing
Web Server Usage
There Are Two Worlds Apache/Open Source PHP  JSP J2EE Servlets Linux Servers MySQL DB ASP possible with Chillisoft (now Sun ASP) Microsoft IIS ASP, ASP.NET Windows 2000 Server Write in C#  MS SQL Server 2000 Develop with Visual Studio .Net
Which World Is Best? Open Source Free or nearly so Cheap hosting Excellent Performance May need to spend money to make scalable (JBOSS free) Development tools OK but the best ones not free Microsoft Expect to spend £10,000 on software Hosting expensive Excellent Performance – more scalable  Compelling ease of development
Megagamez Has Only £70 in the Bank We will use for Apache/MySQL/PHP We will design our database tables We will design our security idea We will make it work First of all let’s understand PHP
PHP History 1994: Created by Rasmis Lesdorf, a software engineer in Apache Team 1995: Called Personal Home Page Tool 1997: used by 50,000 web sites 1998: used by 100,000 websites 1999: used by 1,000,000 websites 2002: 30% of Web sites uses PHP
http://www.netcraft.com/Survey It's BIG
PHP Is Open-source Easy to use but not pretty Stable and fast Runs on all platforms Supports all databases  Has some useful libraries Pre-installed in Linux distributions
How It Works Cache of compiled pages
Or in Words… The Client from browser sends an HTTP request (with POST/GET variables) Apache recognizes that a PHP script is requested and sends the request to PHP module The PHP interpreter executes the PHP script and returns the script output  Apache replies to client using the PHP script output interspersed with HTML output
“Hello World” in PHP <html> <head> <title>My personal Hello World! PHP script</title> </head> <body> <? echo “Hello World!”; ?> </html>
How Do You Run It? See:  http://www.cs.nott.ac.uk/TSG/manuals/webpages/php/ #!/usr/local/bin/php  // 1 st  line of script mkdir ~/cgi-bin  chmod 711 ~/. ~/cgi-bin  (sorry!) chmod 755 *.php URL is http:// robin.cs.nott.ac.uk/~<you>/cgi-bin/test.php
Using Variables Variables start with a  $ The assignment operator is  = No need to declare variables Variables type is implicit No check on variable used before it is assigned Arrrrrrrrrgh… Reminiscent of BASIC - for the cowboys? (wja says so)
An Example A string is a sequence of characters in quotes for example “This is a String” and ‘so is this’ A string can be assigned to a variable: $Homer = “The next president” $Homer = ‘The next president’ Both work…
Substitution in Strings $age = 37 $Homer = “Mr Simpson is $age” $Homer is  Mr Simpson is 37 This does not work in single quotes Which would come out as: Mr Simpson is $age
This Is Slightly Scary to Me $A = 1; $B = “2”; $C = ($A + $B);  // Integer sum $D = $A . $B;  // String catenation echo $C;  // prints 3 echo $D; //  prints 12
I Do Like the  Explode  Function – Good for csv $sequence = “A,B,C,D,E,F,G”; $elements = explode (“,”,$sequence); // Now elements is an array with all substrings between “,” char echo $elemets[0]; // output: A; echo $elemets[1]; // output: B; echo $elemets[2]; // output: C; echo $elemets[3]; // output: D; echo $elemets[4]; // output: E; echo $elemets[5]; // output: F; echo $elemets[6]; // output: G;
Arrays $books = array( ”Enduring Love”,”The Child in Time”,”The Cement Garden”); for ($i=0; $i < count($books); $i++)  print ($i+1).”: $books[$i]”;
Arrays As a Key->element Mapping $students = array( 0=>”Mike”, 1=>”Bill”, 2=>”Fred”, 3=>”Ann”) echo $students[2];  Fred Echo $students[“Fred”];  2 In other words PHP arrays are associative
More on Array Maps $books = array(”Enduring Love”=>1,” The Child in Time”=> 2,” The Cement Garden”=>3); while ($item = each( $books ))  print $item[“value”].” : ”.$item[“key”]; 1 : Enduring Love 2 : The Child in Time 3 : The Cement Garden
Connecting to a Database <?php  //connect to database  $conn=mysql_connect(“sauron.cs.nott.ac.uk&quot;,“usr&quot;,“pwd&quot;) or die(“could not connect to database “.mysql_error()); mysql_select_db(“megagamez”) or die(“message”);  // do something ……… //disconnect from database  mysql_close($conn); ?>
Executing Database Queries <?php  $query = &quot;SELECT name, age, phone FROM students  WHERE (name LIKE '%Smith%')&quot;;  //execute query  $result = mysql_execute($query);  while($row = mysql_fetch_array($result)) { echo($row[“name”].”, “); echo($row[“age”]); } ?>  WOW! That was Easy!
You Will Want More Control Over the Format – So Make a Table <table width=&quot;75%&quot; border=&quot;1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;1&quot; bgcolor=&quot;#FFFFFF&quot;>    <tr bgcolor=&quot;#CCFFFF&quot;>       <td height=&quot;22&quot;><b>Name</b></td>      <td height=&quot;22&quot;><b>Age</b></td>      <td height=&quot;22&quot;><b>Telephone</b></td>    </tr>  … some php stuff </table>
What About Inserting Data? I cannot do better than the excellent tutorial which makes a web site of jokes: http://www.zend.com/zend/tut/tutorial-yank.php
Learning More About PHP Try  http://www.php.net/manual/ Books: O’Reilly Press,  Web Database Applications with PHP and MySQL   Hugh E Williams ,  David Lane
Learning More About PHP You may prefer

More Related Content

PDF
Inside Bokete: Web Application with Mojolicious and others
PDF
RESTful web services
PPT
jQuery Performance Rules
PPT
Php Tutorial | Introduction Demo | Basics
KEY
Mojo as a_client
PDF
Mojolicious
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Inside Bokete: Web Application with Mojolicious and others
RESTful web services
jQuery Performance Rules
Php Tutorial | Introduction Demo | Basics
Mojo as a_client
Mojolicious
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)

What's hot (19)

PPTX
Phphacku iitd
PDF
Web Design EJ3
PDF
Mojolicious: what works and what doesn't
PDF
Developing apps using Perl
PPTX
PHP for hacks
PPT
Php, mysq lpart1
PDF
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
PDF
Blog Hacks 2011
PDF
basic concept of php(Gunikhan sonowal)
PPTX
Php Training Workshop by Vtips
PDF
YAPC::Asia 2010 Twitter解析サービス
PPT
Programming For Designers V3
PPT
Php mysql
ODP
Writing webapps with Perl Dancer
PDF
Twib in Yokoahma.pm 2010/3/5
PDF
Php, mysq lpart4(processing html form)
KEY
Using PHP
KEY
Keeping it small: Getting to know the Slim micro framework
PDF
Ruby on Rails Presentation
Phphacku iitd
Web Design EJ3
Mojolicious: what works and what doesn't
Developing apps using Perl
PHP for hacks
Php, mysq lpart1
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Blog Hacks 2011
basic concept of php(Gunikhan sonowal)
Php Training Workshop by Vtips
YAPC::Asia 2010 Twitter解析サービス
Programming For Designers V3
Php mysql
Writing webapps with Perl Dancer
Twib in Yokoahma.pm 2010/3/5
Php, mysq lpart4(processing html form)
Using PHP
Keeping it small: Getting to know the Slim micro framework
Ruby on Rails Presentation
Ad

Viewers also liked (7)

PPT
A Slide!
PPT
Automation as a Competitive Adv - no notes
PPT
PowerPoint
PDF
News - web host guide - Cheap Web Hosting
PPT
Windows Server Virtualization
PPT
INLS461_day14a.ppt
PPT
A Slide!
Automation as a Competitive Adv - no notes
PowerPoint
News - web host guide - Cheap Web Hosting
Windows Server Virtualization
INLS461_day14a.ppt
Ad

Similar to Building an e:commerce site with PHP (20)

PPTX
Ch1(introduction to php)
PPT
Going crazy with Node.JS and CakePHP
PPTX
Php 101 by David Menendez
ODP
Modern Perl
PDF
lab4_php
PDF
lab4_php
PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PPT
ODP
PHP: The easiest language to learn.
PDF
2014 database - course 2 - php
PPT
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
ODP
Perl Moderno
PPT
PHP 5 Sucks. PHP 5 Rocks.
PPTX
HackU PHP and Node.js
PPT
Php introduction
PDF
Lecture8
PDF
Hiveminder - Everything but the Secret Sauce
PPT
Phpwebdevelping
PPT
Starting with PHP and Web devepolment
PPTX
PSGI and Plack from first principles
Ch1(introduction to php)
Going crazy with Node.JS and CakePHP
Php 101 by David Menendez
Modern Perl
lab4_php
lab4_php
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PHP: The easiest language to learn.
2014 database - course 2 - php
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
Perl Moderno
PHP 5 Sucks. PHP 5 Rocks.
HackU PHP and Node.js
Php introduction
Lecture8
Hiveminder - Everything but the Secret Sauce
Phpwebdevelping
Starting with PHP and Web devepolment
PSGI and Plack from first principles

More from webhostingguy (20)

PPT
File Upload
PDF
Running and Developing Tests with the Apache::Test Framework
PDF
MySQL and memcached Guide
PPT
Novell® iChain® 2.3
PDF
Load-balancing web servers Load-balancing web servers
PDF
SQL Server 2008 Consolidation
PDF
What is mod_perl?
PDF
What is mod_perl?
PDF
Master Service Agreement
PPT
PDF
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
PPT
Managing Diverse IT Infrastructure
PPT
Web design for business.ppt
PPS
IT Power Management Strategy
PPS
Excel and SQL Quick Tricks for Merchandisers
PPT
OLUG_xen.ppt
PPT
Parallels Hosting Products
PPT
Microsoft PowerPoint presentation 2.175 Mb
PDF
Reseller's Guide
PDF
Installation of MySQL 5.1 Cluster Software on the Solaris 10 ...
File Upload
Running and Developing Tests with the Apache::Test Framework
MySQL and memcached Guide
Novell® iChain® 2.3
Load-balancing web servers Load-balancing web servers
SQL Server 2008 Consolidation
What is mod_perl?
What is mod_perl?
Master Service Agreement
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Managing Diverse IT Infrastructure
Web design for business.ppt
IT Power Management Strategy
Excel and SQL Quick Tricks for Merchandisers
OLUG_xen.ppt
Parallels Hosting Products
Microsoft PowerPoint presentation 2.175 Mb
Reseller's Guide
Installation of MySQL 5.1 Cluster Software on the Solaris 10 ...

Building an e:commerce site with PHP

  • 2. To Implement Megagamez’s Web Site: We need to build shopping trolley contents in a database We need to keep track of our customers and orders We will use MySQL and PHP to do this
  • 3. Client-side and Server-side Scripting Client-side Javascript VBScript (MS) Can be used to validate input Can implement mouse-over effects etc Server-side cgi PHP ASP ASP.NET JSP Perl & Ruby – these ugly sisters will not be studied in ELC Communicates with database Application logic
  • 6. There Are Two Worlds Apache/Open Source PHP JSP J2EE Servlets Linux Servers MySQL DB ASP possible with Chillisoft (now Sun ASP) Microsoft IIS ASP, ASP.NET Windows 2000 Server Write in C# MS SQL Server 2000 Develop with Visual Studio .Net
  • 7. Which World Is Best? Open Source Free or nearly so Cheap hosting Excellent Performance May need to spend money to make scalable (JBOSS free) Development tools OK but the best ones not free Microsoft Expect to spend £10,000 on software Hosting expensive Excellent Performance – more scalable Compelling ease of development
  • 8. Megagamez Has Only £70 in the Bank We will use for Apache/MySQL/PHP We will design our database tables We will design our security idea We will make it work First of all let’s understand PHP
  • 9. PHP History 1994: Created by Rasmis Lesdorf, a software engineer in Apache Team 1995: Called Personal Home Page Tool 1997: used by 50,000 web sites 1998: used by 100,000 websites 1999: used by 1,000,000 websites 2002: 30% of Web sites uses PHP
  • 11. PHP Is Open-source Easy to use but not pretty Stable and fast Runs on all platforms Supports all databases Has some useful libraries Pre-installed in Linux distributions
  • 12. How It Works Cache of compiled pages
  • 13. Or in Words… The Client from browser sends an HTTP request (with POST/GET variables) Apache recognizes that a PHP script is requested and sends the request to PHP module The PHP interpreter executes the PHP script and returns the script output Apache replies to client using the PHP script output interspersed with HTML output
  • 14. “Hello World” in PHP <html> <head> <title>My personal Hello World! PHP script</title> </head> <body> <? echo “Hello World!”; ?> </html>
  • 15. How Do You Run It? See: http://www.cs.nott.ac.uk/TSG/manuals/webpages/php/ #!/usr/local/bin/php // 1 st line of script mkdir ~/cgi-bin chmod 711 ~/. ~/cgi-bin (sorry!) chmod 755 *.php URL is http:// robin.cs.nott.ac.uk/~<you>/cgi-bin/test.php
  • 16. Using Variables Variables start with a $ The assignment operator is = No need to declare variables Variables type is implicit No check on variable used before it is assigned Arrrrrrrrrgh… Reminiscent of BASIC - for the cowboys? (wja says so)
  • 17. An Example A string is a sequence of characters in quotes for example “This is a String” and ‘so is this’ A string can be assigned to a variable: $Homer = “The next president” $Homer = ‘The next president’ Both work…
  • 18. Substitution in Strings $age = 37 $Homer = “Mr Simpson is $age” $Homer is Mr Simpson is 37 This does not work in single quotes Which would come out as: Mr Simpson is $age
  • 19. This Is Slightly Scary to Me $A = 1; $B = “2”; $C = ($A + $B); // Integer sum $D = $A . $B; // String catenation echo $C; // prints 3 echo $D; // prints 12
  • 20. I Do Like the Explode Function – Good for csv $sequence = “A,B,C,D,E,F,G”; $elements = explode (“,”,$sequence); // Now elements is an array with all substrings between “,” char echo $elemets[0]; // output: A; echo $elemets[1]; // output: B; echo $elemets[2]; // output: C; echo $elemets[3]; // output: D; echo $elemets[4]; // output: E; echo $elemets[5]; // output: F; echo $elemets[6]; // output: G;
  • 21. Arrays $books = array( ”Enduring Love”,”The Child in Time”,”The Cement Garden”); for ($i=0; $i < count($books); $i++) print ($i+1).”: $books[$i]”;
  • 22. Arrays As a Key->element Mapping $students = array( 0=>”Mike”, 1=>”Bill”, 2=>”Fred”, 3=>”Ann”) echo $students[2]; Fred Echo $students[“Fred”]; 2 In other words PHP arrays are associative
  • 23. More on Array Maps $books = array(”Enduring Love”=>1,” The Child in Time”=> 2,” The Cement Garden”=>3); while ($item = each( $books )) print $item[“value”].” : ”.$item[“key”]; 1 : Enduring Love 2 : The Child in Time 3 : The Cement Garden
  • 24. Connecting to a Database <?php //connect to database $conn=mysql_connect(“sauron.cs.nott.ac.uk&quot;,“usr&quot;,“pwd&quot;) or die(“could not connect to database “.mysql_error()); mysql_select_db(“megagamez”) or die(“message”);  // do something ……… //disconnect from database mysql_close($conn); ?>
  • 25. Executing Database Queries <?php $query = &quot;SELECT name, age, phone FROM students  WHERE (name LIKE '%Smith%')&quot;; //execute query $result = mysql_execute($query); while($row = mysql_fetch_array($result)) { echo($row[“name”].”, “); echo($row[“age”]); } ?> WOW! That was Easy!
  • 26. You Will Want More Control Over the Format – So Make a Table <table width=&quot;75%&quot; border=&quot;1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;1&quot; bgcolor=&quot;#FFFFFF&quot;>   <tr bgcolor=&quot;#CCFFFF&quot;>      <td height=&quot;22&quot;><b>Name</b></td>     <td height=&quot;22&quot;><b>Age</b></td>     <td height=&quot;22&quot;><b>Telephone</b></td>   </tr> … some php stuff </table>
  • 27. What About Inserting Data? I cannot do better than the excellent tutorial which makes a web site of jokes: http://www.zend.com/zend/tut/tutorial-yank.php
  • 28. Learning More About PHP Try http://www.php.net/manual/ Books: O’Reilly Press, Web Database Applications with PHP and MySQL   Hugh E Williams , David Lane
  • 29. Learning More About PHP You may prefer