Download presentation
Presentation is loading. Please wait.
Published byJody Walton Modified over 9 years ago
1
Intro to LAMP Programming Presented for CIS Faculty at SAC by Dan Zollars
2
What is LAMP? Linux Apache MySQL PHP Number one HTTP server on the Internet Most popular open-source database Widely used, general purpose scripting language
3
Getting Started Website resources – see http://cis.sac.accd.edu/~dzollars, then LAMP demo http://cis.sac.accd.edu/~dzollars Need only vi editor and browser – working directly on sol using programs already set up Put programs in public_html under personal directory
4
Topics Testing Apache & PHP Integrating PHP and HTML Targeting a PHP script from an HTML form Retrieving information from MySQL databases Accessing MySQL databases from PHP Practice
5
Testing Apache & PHP In browser: http://cis.sac.accd.edu/~yourname Any document in public_html is available for Apache to serve to client (even if no link) /home/yourname/public_html/sample.html http://cis.sac.accd.edu/~yourname/sample.html Using Minimal XHTML document Testing PHP: Example 1
6
Integrating PHP & HTML \$i = $i \n”; // more php code ?> Example 2
7
Targeting a PHP script Now in target.php: $field_name = $_POST['field_name']; Example 3
8
Practice - 1 Write the target script for example3.php
9
Practice - 1 (answers) The name you entered was: $lastname \n"; ?>
10
Retrieving MySQL Information SELECT { | *} FROM [,...] [WHERE ] [ORDER BY [DESC] ] [GROUP BY ] ;
11
SELECT Clause Use the SELECT clause to restrict which columns to display SELECT firstname, lastname, email SELECT qty, item_desc SELECT *
12
FROM Clause Use the FROM clause to specify which table(s) to retrieve the data from SELECT firstname, lastname, email FROM customers; SELECT * FROM orders;
13
WHERE Clause Use the WHERE clause to restrict the number of rows to display SELECT qty, item_desc FROM items WHERE qty > 1; SELECT * FROM orders WHERE paid IS NULL;
14
JOINS Several kinds Common column Can use either the FROM or WHERE clause
15
JOIN - WHERE 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 qty, item_desc FROM items, orders WHERE items.order_id = orders.order_id AND items.order_id = 1002;
16
Practice - 2 Use the satlug database to find out the following: Names and addresses of all the customers How many orders for each customer (just list them and count)? List the unfinished orders (completed IS NULL) 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)?
17
Practice - 2 (answers) SELECT firstname, lastname, address, city, state FROM customers; SELECT * FROM orders; SELECT * FROM orders WHERE completed IS NULL;
18
Practice - 2 (answers) 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;
19
Accessing MySQL from PHP $link = mysql_connect(“host”, “name”, “pw”); mysql_select_db(“satlug”, $link); $result = mysql_query($query); while ($row = mysql_fetch_array($result)) echo “$row[0] $row[1] \n”;// etc. die(“Error message”. mysql_error()); Example 4
20
Practice - 3 Modify example 3 source and target as follows: 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 order_id, target displays qty and description
21
Using $_GET In source file, create a link with parameter Text In target file, use $_GET superglobal to get info $id = $_GET['id']; Creates different html for each table entry Still only two files
22
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.