Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Four Instructor:

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

NEVUG - August 2004 To Boldly Go: Using Perl and the Perl DBI as an Adjunct to MS Access for Custom Reports Maggie Rioux MBLWHOI Library Woods Hole, Mass.
What is MySQL? MySQL is a relational database management system (A relational database stores data in separate tables rather than putting all the data.
Implementing Session Support COEN 351. State Maintenance Client Side Mechanisms  Cookies Client needs to allow cookies Cookie handling done by browser.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
1 SQL (CSCE 330) Team Members Bushira Kiyemba La’Trice Johnson Curtis Merriweather.
Project Implementation for COSC 5050 Distributed Database Applications Lab6.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class One Instructor:
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Session 5: Working with MySQL iNET Academy Open Source Web Development.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
Introduction to InfoSec – Recitation 7 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
DBI tutorial February 5 th, What is DBI DBI is short for Database Interface, which is a Perl module DBI is short for Database Interface, which is.
Python MySQL Database Access
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Programming in Facebook hussein suleman uct cs honours 2007.
1 Working with MS SQL Server Textbook Chapter 14.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
INDIANAUNIVERSITYINDIANAUNIVERSITY OneStart page types  Tab – pages across the top, immutable  Section – pages down the left  Subsection – pages under.
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.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
Databases On The Web with perl Archie Warnock
Creating PHPs to Insert, Update, and Delete Data CS 320.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
CSC3530 Software Technology Tutorial One Assignment overview & HTML basics.
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Dr. Venton Kepuska Donald L. Troup. Dynamic Web Calendar
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
1 Final Review. 2 Final Exam  30% of your grade for the course  December 9 at 7:00 p.m., the regular class time  No makeup exam or alternate times.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 1 Intermediate Perl Programming Class Two Instructor:
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
DBI: The Neophyte's Guide1 What is DBI? DBI = DataBase Interface DBI is database-independent DBI allows you to write code that interacts with databases.
SQL. What is a database? G a collection of data G Usually consists of entities and relations G An entity is an individual “object” that exists and is.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Five Instructor:
Getting Your Content in the Penn State Student Portal Presented By James Leous, Program Manager James Vuccolo, Lead Research Programmer.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Lab 3.21 MySQL Database Lab Developing the Tools May 5 th, 2004 Montréal, Québec Dominik Gehl Hôpital Ste-Justine, Montréal.
XML 1.Introduction to XML 2.Document Type Definition (DTD) 3.XML Parser 4.Example: CGI Gateway to XML Middleware.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
Revision Lecture: HTML, CSS and XML Perl/CGI, Perl/DOM, Perl/DBI, Remote Procedure Calls Dr. Andrew C.R. Martin
Introduction to Dynamic Web Programming
Pengantar Keamanan Informasi
Web Programming Week 3 Old Dominion University
Perl Database – Just Enough
Advanced Topics Web Programming.
Chapter 8 Working with Databases and MySQL
Web Programming Week 3 Old Dominion University
CPSC-608 Database Systems
Web Programming Week 3 Old Dominion University
Presentation transcript:

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Four Instructor: Byrne Reese X401

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Review from Last Week… 1.Web Automation 2.Writing a “Remember Me” web app using Cookies 3.Discussion of “Sessions” and Cookie/Session Security 4.Quick SQL Primer 5.Homework: Writing a Link Checker

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Today’s Agenda 1.Homework Review 2.Fast SQL Primer 3.MySQL and other free databases 4.DBI Module

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Homework Review Write a link checker: –Takes as input a single URL –For each href located on that page, verify that the link is valid. –Print out the links to validate and their status as you go. Hints: –Regular expressions to extract URLs –URI::Find

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. SQL Primer

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. About SQL Structured Query Language Standard

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Our Database Table 1: “users” –user_id (primary key) –username –password Table 2: “bookmarks” –user_id (foreign key) –link –label

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Setup the Database  scp Password: “iloveperl”  mysqladmin create –u root perlclass  mysql –u root perlclass < schema_data.sql  mysql –u root perlclass

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. INSERT Statement Adds a single row to the selected database table Example: INSERT INTO users (username, password) VALUES (‘byrne’,’reese’);

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. UPDATE Statement Modifies a row or rows in the selected database table Example: UPDATE users SET password=‘reese’ WHERE username=‘byrne’

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. DELETE Statement Deletes a row or rows in the selected database table Example: DELETE FROM users WHERE username=‘byrne’

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. SELECT Statement Reads a row or rows in the selected database table Example: SELECT username,password FROM users WHERE username=‘john’

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. JOINs Selects and associates data located in two different tables into a single result set. Primary keys and Foreign keys Example: SELECT b.label, b.link FROM users u, bookmarks b WHERE u.username=‘byrne’ AND u.user_id = b.user_id

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. 15 Minute Break

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Using Perl’s DBI Installing DBI and DBD::mysql Connecting to the Database Preparing a Statement Executing a Statement Executing a Query and parsing the results

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Connecting to the Database Database “Handles” Example: connect_to_db(): use DBI; sub connect_to_db { my $dbh = DBI->connect("DBI:mysql:$DB:$DBHOST", "$DBUSER","$DBPASS",{RaiseError => 1}) or die "connecting : $DBI->errstr\n"; return $dbh; }

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Executing a Statement Example: my $dbh = connect_to_db(); my $sql = "DELETE FROM users"; my $sth = $dbh->prepare($sql); $sth->execute; $sth->finish; $dbh->close;

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Executing a Query Example: my $dbh = connect_to_db(); my $sql = "SELECT username,password FROM users"; my $sth = $dbh->prepare($sql); $sth->execute; while (($username,$password) = $sth->fetchrow) { print “username=$username, password=$password\n”; }

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. XML

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. XML Primer eXtensible Markup Language Why use XML? –It’s Simple –It’s Extensible –It’s a Standard –It’s Descriptive –It’s Describable

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. XML in the Real World Web Services –Amazon –eBay –PayPal –Salesforce.com Blogs –Atom and RSS Feedburner Google Maps

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. XML Primer XML Syntax –Well formed-ness –Valid Parsers –DOM –SAX

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Sample XML File Example: intperl.xml: Intermediate Perl Byrne Reese 18:30Z-09:00 Paul Elaine Vladimir

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. XML Modules XML::Parser XML::SAX XML::Simple

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. XML::Simple – Reading XML Code Sample: #!/usr/bin/perl use XML::Simple; my $xmldata = XMLin(“intperl.xml”); print $xmldata->students->student->[1];

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. XML::Simple – Writing XML Code Sample: #!/usr/bin/perl use XML::Simple; my $xmldata = { name => ‘Intermediate Perl’, instructor => ‘Byrne Reese’, schedule => { time => ’18:30Z-09:00’ }, students => { student => [ ‘Paul’,’Elaine’,’Vladimir’ ] } my $xml = XMLout($xmldata);

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Debugging Data::Dumper –Stringifies Perl data structures Code sample: #!/usr/bin/perl use XML::Simple; use Data::Dumper; my $xmldata = XMLin(“intperl.xml”); print Dumper($xmldata);

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Exercise 1 In class: parse and display the contents of an RSS feed. – At home: take a URL to an RSS feed as a command line argument, scrape that page and then display the contents. Hint: “man XML::Simple”

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Homework Your choice of one of two exercises: –Exercise 1 - XML Exercise –Exercise 2 - Database Exercise

Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Exercise 2 Create an address book: –Write subroutines capable of creating, reading, updating and deleting (CRUD) a single row in the database Extra Credit: –Make it command line accessible