Intro to LAMP Programming Presented for SAT Linux Users' Group by Dan Zollars.

Slides:



Advertisements
Similar presentations
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Advertisements

PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
Web Database Programming Connecting Database to Web.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
PHP and MySQL PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
Objectives Connect to MySQL from PHP
Multiple Tiers in Action
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
Database Basics CS Why use a database?  powerful: can search it, filter data, combine data from multiple sources  fast: can search/filter a database.
Web Page A page displayed by the browser. Website Collection of multiple web pages Web Browser: A software that displays web pages on client computer.
PHP-MySQL By Jonathan Foss. PHP and MySQL Server Web Browser Apache PHP file PHP MySQL Client Recall the PHP architecture PHP can communicate with a MySQL.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
IT 210 The Internet & World Wide Web introduction.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
02/09/2015 Intro PHP & MySQL 1 Helen Hastie Room: EMB244 Material available on Vision (modified from slides by Monica Farrow) F27DB Introduction.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
INTERNET APPLICATION DEVELOPMENT For More visit:
Server-side Scripting Powering the webs favourite services.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Multifarious Project Team Members Alberto Dominguez Nirmit Gang Jimmy Garcia Javier Handal.
Unit Seven Database 1.Passage One. Foundation of Database.
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
SQL Queries Relational database and SQL MySQL LAMP SQL queries A MySQL Tutorial and applications Database Building Assignment.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
MySQL and PHP 3 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
MySQL PHP Web Technology. Logging in to Command Line Start -> Programs -> AppServ -> MySQL Command Line Client Enter Password, then you’ll be working.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Intro to LAMP Programming Presented for CIS Faculty at SAC by Dan Zollars.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
1 Welcome to CSC 301 Web Programming Charles Frank.
CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Basic HTML HTML document consists of text markup tags interspersed in the text Example: Example 1 Example 1 Here goes the text This is a second paragraph.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Drilling down Restrictions on data interaction between browser and server a new connection has to be made for each interaction Solution: break up the data.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Open Source Server Side Scripting Permissions & Users
PHP / MySQL Introduction
Database Driven Websites
ISC440: Web Programming 2 Server-side Scripting PHP 3
PHP and MySQL.
Presentation transcript:

Intro to LAMP Programming Presented for SAT Linux Users' Group by Dan Zollars

What is LAMP? Linux Apache MySQL PHP Linux Apache MySQL PHP Number one HTTP server on the Internet Number one HTTP server on the Internet Most popular open-source database Most popular open-source database Widely used, general purpose scripting language Widely used, general purpose scripting language

Getting Started Website resources – see then LAMP demo Website resources – see then LAMP demo Need text editor and browser – programs are already set up Need text editor and browser – programs are already set up Root access Root access Apache document root: /var/www/htdocs Apache document root: /var/www/htdocs Client – Server model Client – Server model

Topics Testing Apache & PHP Testing Apache & PHP Integrating PHP and HTML Integrating PHP and HTML Targeting a PHP script from an HTML form Targeting a PHP script from an HTML form Retrieving information from MySQL databases Retrieving information from MySQL databases Accessing MySQL databases from PHP Accessing MySQL databases from PHP Practice Practice

Testing Apache & PHP In browser: In browser: Any document in document root is available for Apache to serve to client Any document in document root is available for Apache to serve to client /var/www/htdocs/sample.html same as /var/www/htdocs/sample.html same as Using Minimal XHTML document Using Minimal XHTML document Testing PHP: Example 1 Testing PHP: Example 1

Integrating PHP & HTML \$i = $i \n”; // more php code ?> \$i = $i \n”; // more php code ?> Example 2 Example 2

Targeting a PHP script Now in target.php: $field_name = $_POST['field_name']; Now in target.php: $field_name = $_POST['field_name']; Example 3 Example 3

Practice - 1 Write the target script for example3.php Write the target script for example3.php

Practice - 1 (answers) The name you entered was: $lastname \n"; ?> The name you entered was: $lastname \n"; ?>

Retrieving MySQL Information SELECT { | *} FROM [,...] [WHERE ] [ORDER BY [DESC] ] [GROUP BY ] ;

SELECT Clause Use the SELECT clause to restrict which columns to display Use the SELECT clause to restrict which columns to display SELECT firstname, lastname, SELECT firstname, lastname, SELECT qty, item_desc SELECT qty, item_desc SELECT * SELECT *

FROM Clause Use the FROM clause to specify which table(s) to retrieve the data from Use the FROM clause to specify which table(s) to retrieve the data from SELECT firstname, lastname, FROM customers; SELECT firstname, lastname, FROM customers; SELECT * FROM orders; SELECT * FROM orders;

WHERE Clause Use the WHERE clause to restrict the number of rows to display Use the WHERE clause to restrict the number of rows to display SELECT qty, item_desc FROM items WHERE qty > 1; SELECT qty, item_desc FROM items WHERE qty > 1; SELECT * FROM orders WHERE paid IS NULL; SELECT * FROM orders WHERE paid IS NULL;

JOINS Several kinds Several kinds Common column Common column Can use either the FROM or WHERE clause Can use either the FROM or WHERE clause

JOIN - WHERE Uses the WHERE clause to specify join condition Uses the WHERE clause to specify join condition SELECT order_id, order_date, lastname FROM orders, customers WHERE orders.cust_id = customers.cust_id; SELECT order_id, order_date, lastname FROM orders, customers WHERE orders.cust_id = customers.cust_id; SELECT qty, item_desc FROM items, orders WHERE items.order_id = orders.order_id AND items.order_id = 1002; SELECT qty, item_desc FROM items, orders WHERE items.order_id = orders.order_id AND items.order_id = 1002;

Miscellaneous MySQL mysql -p mysql -p show databases; show databases; use ; use ; show tables; show tables; describe ; describe ; grant all on testing.* to identified by “Yabba%Dabba&Do”; grant all on testing.* to identified by revoke on testing.* from revoke on testing.* from

Security in MySQL Daemon/client architecture Daemon/client architecture Run daemon as mysql user Run daemon as mysql user Require passwords Require passwords USE mysql; USE mysql; SELECT host, user, password FROM user; SELECT host, user, password FROM user; Set up non-root user for specific databases Set up non-root user for specific databases

Practice - 2 Use the satlug database to find out the following: Use the satlug database to find out the following: Names and addresses of all the customers Names and addresses of all the customers How many orders for each customer (just list them and count)? How many orders for each customer (just list them and count)? List the unfinished orders (completed IS NULL) List the unfinished orders (completed IS NULL) List the orders that have been shipped but haven't been paid for yet List the orders that have been shipped but haven't been paid for yet How many carrots did Bugs Bunny order (join items to orders where cust_id = 4)? How many carrots did Bugs Bunny order (join items to orders where cust_id = 4)?

Practice - 2 (answers) SELECT firstname, lastname, address, city, state FROM customers; SELECT firstname, lastname, address, city, state FROM customers; SELECT * FROM orders; SELECT * FROM orders; SELECT * FROM orders WHERE completed IS NULL; SELECT * FROM orders WHERE completed IS NULL;

Practice - 2 (answers) SELECT * FROM orders WHERE completed IS NOT NULL AND paid IS NULL; SELECT * FROM orders WHERE completed IS NOT NULL AND paid IS NULL; SELECT qty, item_desc FROM items, orders WHERE items.order_id = orders.order_id AND orders.cust_id = 4; SELECT qty, item_desc FROM items, orders WHERE items.order_id = orders.order_id AND orders.cust_id = 4;

Accessing MySQL from PHP $link = mysql_connect(“host”, “name”, “pw”); $link = mysql_connect(“host”, “name”, “pw”); mysql_select_db(“satlug”, $link); mysql_select_db(“satlug”, $link); $result = mysql_query($query); $result = mysql_query($query); while ($row = mysql_fetch_array($result)) echo “$row[0] $row[1] \n”;// etc. while ($row = mysql_fetch_array($result)) echo “$row[0] $row[1] \n”;// etc. die(“Error message”. mysql_error()); die(“Error message”. mysql_error()); Example 4 Example 4

Practice - 3 Modify example 3 source and target as follows: Modify example 3 source and target as follows: Client enters last name, target displays first and last names Client enters last name, target displays first and last names Client enters cust_id, target displays order id and order date for all orders Client enters cust_id, target displays order id and order date for all orders Client enters order_id, target displays qty and description Client enters order_id, target displays qty and description

Using $_GET ● In source file, create a link with parameter ● Text ● Text ● In target file, use $_GET superglobal to get info ● $id = $_GET['id']; ● Creates different html for each table entry ● Still only two files

Practice - 4 ● Modify practice 3 source and target as follows: ● Source looks up customer names, presents as links to target using HTTP parameter (display name, use id as parameter) ● Target uses $_GET to determine cust_id, then looks up other customer information ● Target displays information

PHP Review What's wrong with this: What's wrong with this: echo " Zollars' real name is "$dufus" "; echo " Zollars' real name is "$dufus" "; $query = “SELECT fname, lname “. “FROM customers “. “WHERE department = Admin “; $query = “SELECT fname, lname “. “FROM customers “. “WHERE department = Admin “; $query = “SELECT qty, desc “. “FROM inventory “. “WHERE partno LIKE 'L%'; $query = “SELECT qty, desc “. “FROM inventory “. “WHERE partno LIKE 'L%';

PHP Odds and Ends PHP Provides lots of useful things: PHP Provides lots of useful things: include() or include_once(); include() or include_once(); include_once(“connect.php”); include_once(“connect.php”); include(“header.php”); include(“header.php”); foreach ($a as $x) foreach ($a as $x) Associative arrays Associative arrays $state['TX'] = “Texas”; $state['TX'] = “Texas”; foreach ($state as $key=>$name) echo “ $key is the state of $name ” foreach ($state as $key=>$name) echo “ $key is the state of $name ”