1 / 11

BOF #2 – Introduction to PHP and MySQL

This CTO-level technical introduction explains the key concepts of PHP and MySQL, the client-server model, and the process of putting it all together. The session is interactive with relevant Q&A throughout. Laptops are welcome but not required. Community involvement is encouraged, and participants can lead their own BOF sessions.

amontoya
Download Presentation

BOF #2 – Introduction to PHP and MySQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BOF #2 – Introduction to PHP and MySQL Bootup Open Forums CTO-level technical introduction to key technology Interactive throughout – relevant Q&A will drive content Laptops welcome although not required (not yet) Semi-weekly – recommend topics yourself Community involved - lead a BOF yourself

  2. Introduction to PHP and MySQLThe Dynamic Duo for a Dynamic Web Hans Zaunere, Managing Member BOF #2 April 12th, 2010

  3. Overview The Cast and Key Concepts HTTP The Request The Process The Database Putting it All Together

  4. The Cast HTTP, Apache, MySQL and PHP • Key concept: client – server model • This exchange is the request-response cycle • HTTP – Protocol used to communicate • Apache – The web server • MySQL – Provides content/data to display • PHP – PHPHypertext Preprocessor within Apache • AMP: Acronym for three key software components • Basis of modern, dynamic, web/internet applications

  5. HTTP HyperText-Transfer-Protocol • Key concept: stateless • After request-response cycle is over, neither knows of each other • One of the issues of security or “hi-jacking” • Cookies are utilized to maintain a session • Server keeps knowledge that a client existed, identified by a cookie left on the browser • For such things as knowing whether a user is logged in or not • Different types of requests • GET – includes optional query string –read-only • POST – can also include query string – write or read • HyperTextTransfer Protocol Secure – HTTPS • Encrypts the communication channel through a SSL certificate

  6. The Request Telling PHP What To Do • PHP is designed to handle HTTP communication • Apache module (other options are available) • Embedded into HTML using <?phpand ?> tags • Provides “super-globals” for accessing information about the request • $_GET – GET query string variables • $_POST – POST variables • $_COOKIE – Other cookie variables • $_SESSION – Internal session information using a session ID

  7. The Process HTML – The “Goods” • PHP is designed to process hypertext • HTML is the HyperTextMarkup Language, used for giving structure to the information exchanged on the WWW REQUEST: HTTP/1.1 GET /my-script.php?FirstName=David RESPONSE: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"....> <html> <head> <title>Hello World</title> </head> <body> <b> <?php echo "Hello There ".$_GET['FirstName']; ?> </b> <?php echo 'At the tone, the time will be: '.date('r'); ?> </body> </html> • Browser then receives and renders the HTML • Doesn’t know that it’s been generated dynamically

  8. The Database SQL – The “Supplier” • Data is stored in tables and columns • PHP is designed to communicate with databases • SQL is the Structured Query Language, used for manipulating and retrieving data • SQL is also used for complex or “relational” data SELECT FirstName,LastName, DATE_FORMAT(DoB,'%M, %D, %Y') AS DateOfBirth FROM Users WHERE STRTOUPPER(LEFT(FirstName,1)) = 'H' SELECT FirstName,LastName,Address1,Address2 FROM Users,Address WHERE R_UserID=UserID AND STRTOUPPER(LEFT(FirstName,1)) = 'H'

  9. Putting It All Together Your Cast and Crew – Apache / MySQL / PHP • Web browser uses HTTP to make web server request • Web server passes control to PHP • PHP uses SQL to query the database and fetch data REQUEST: HTTP/1.1 GET /my-script.php?FirstNameFirstLetter=H <?php $FirstNameFirstLetter= mysql_escape_string($_GET['FirstNameFirstLetter']); $Result = mysql_query("SELECT FirstName,LastName, DATE_FORMAT(DoB,'%M, %D, %Y') AS DateOfBirth FROM Users WHERE STRTOUPPER(LEFT(FirstName,1)) = '{$FirstNameFirstLetter}'",$MYDBR); $ResultCount = mysql_num_rows($Result); $ResultArray = array(); for( $i = 0; $i < $ResultCount; ++$i ) { $ResultArray[$i] = mysql_fetch_assoc($Result); } ?>

  10. Putting It All Together The Finale • PHP manipulates returned data and processes HTML • PHP and the web server use HTTPto respond • Web browser receives HTML anddisplays the results <!DOCTYPE...> <ul> <?phpforeach( $ResultArray as $Key => $Row ): ?> <li><?=$Row['LastName']?>, <?=$Row['FirstName']?> (<?=$Row['DateOfBirth']?>)</li> <?phpendforeach; ?> </ul>

  11. Thank You hans.zaunere@nyphp.com New York PHP Mailing Lists are free and available to anyone: http://www.nyphp.org/mailinglists.php

More Related