Validated.php <?php $title="my basic page\n"; include("top.html"); print " hello, world "; include("bottom.html"); ?>

Slides:



Advertisements
Similar presentations
LIS651 lecture 3 taming PHP Thomas Krichel
Advertisements

LIS651 lecture 2 mySQL and PHP mySQL functions Thomas Krichel
LIS651 lecture 3 taming PHP Thomas Krichel
LIS651 lecture 2 databases, mySQL and PHP mySQL functions Thomas Krichel
LIS651 lecture 2 mySQL and PHP mySQL function Thomas Krichel
LIS651 lecture 2 mySQL and PHP mySQL function Thomas Krichel
LIS651 lecture 3 functions & sessions Thomas Krichel
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
LIS512 lecture 2 relational databases Thomas Krichel
PHP (2) – Functions, Arrays, Databases, and sessions.
SQL Data Definition II Stanislava Armstrong 1SQL Data Definition II.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
ADVM420- Class #4 Web Design with PHP and MySQL Adding and Listing from a MySQL Database.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
MySql In Action Step by step method to create your own database.
LIS512 lecture 1 the entity-relationship model Thomas Krichel
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
LIS651 lecture 7 PHP mySQL Thomas Krichel
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
LIS651 lecture 2 mySQL and PHP mySQL function Thomas Krichel
INTERNET APPLICATION DEVELOPMENT For More visit:
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.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Practical Session 13 Structured Data Bases Structured Query Language Exam Questions Factory Method Pattern Abstract Factory Pattern.
LIS651 lecture 5 multiple arrays and databases Thomas Krichel
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
PHP meets MySQL.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
LIS651 lecture 6 mySQL Thomas Krichel
Introduction to MySQL Lab no. 10 Advance Database Management System.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSC 2720 Building Web Applications Database and SQL.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
M1G Introduction to Database Development 2. Creating a Database.
MySQL More… 1. More on SQL In MySQL, the Information Schema is the “Catalog” in the SQL standard SQL has three components: Data definition Data manipulation.
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)
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
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,
Introduction to Teradata Client Tools. 2 Introduction to Teradata SQL  OBJECTIVES :  Teradata Product Components.  Accessing Teradata – Database /
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
LIS651 lecture 3 functions & sessions
CS320 Web and Internet Programming SQL and MySQL
Database application MySQL Database and PhpMyAdmin
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Chapter 4 Introduction to MySQL.
CS3220 Web and Internet Programming SQL and MySQL
Presentation transcript:

validated.php <?php $title="my basic page\n"; include("top.html"); print " hello, world "; include("bottom.html"); ?>

LIS651 lecture 2 Thomas Krichel

today introduction to mySQL more on PHP –functions –includes

Databases Databases are collection of data with some organization to them. The classic example is the relational database. But not all database need to be relational databases.

Relational databases A relational database is a set of tables. There may be relations between the tables. Each table has a number of record. Each record has a number of fields. When the database is being set up, we fix –the size of each field –relationships between tables

Example: Movie database ID| title | director| date M1| Gone with the wind | F. Ford Coppola| 1963 M2| Room with a view| Coppola, F Ford| 1985 M3| High Noon| Woody Allan| 1974 M4 | Star Wars| Steve Spielberg| 1993 M5| Alien| Allen, Woody | 1987 M6| Blowing in the Wind| Spielberg, Steven| 1962 Single table No relations between tables, of course

Problem with this database All data wrong, but this is just for illustration. Name covered inconsistently. There is no way to find films by Woody Allan without having to go through all spelling variations. Mistakes are difficult to correct. We have to wade through all records, a masochist’s pleasure.

Better movie database ID| title | director| year M1| Gone with the wind | D1| 1963 M2| Room with a view| D1| 1985 M3| High Noon| D2| 1974 M4 | Star Wars| D3| 1993 M5| Alien| D2 | 1987 M6| Blowing in the Wind| D3| 1962 ID| director name| birth year D1| Ford Coppola, Francis| 1942 D2| Allan, Woody| 1957 D3| Spielberg, Steven| 1942

Relational database We have a one to many relationship between directors and film –Each film has one director –Each director has produced many films Here it becomes possible for the computer –To know which films have been directed by Woody Allen –To find which films have been directed by a director born in 1942

Many-to-many relationships Each film has one director, but many actors star in it. Relationship between actors and films is a many to many relationship. Here are a few actors ID| sex| actor name| birth year A1| f| Brigitte Bardot | 1972 A2| m| George Clooney| 1927 A3| f| Marilyn Monroe| 1934

Actor/Movie table actor id| movie id A1| M4 A2| M3 A3| M2 A1| M5 A1| M3 A2| M6 A3| M4 … as many lines as required

databases in libraries Relational databases dominate the world of structured data But not so popular in libraries –Slow on very large databases (such as catalogs) –Library data has nasty ad-hoc relationships, e.g. Translation of the first edition of a book CD supplement that comes with the print version Difficult to deal with in a system where all relations and field have to be set up at the start, can not be changed easily later.

databases in web sites Lots of active web sites are driven by relational databases. All large active web sites are. The design of a active web site first involves looking at databases. In a shop situation, we have the following tables –customers –products –orders –orders_products for multiple to multiple relationship between orders and products.

SQL Once we have the relational database, we can ask sophisticated questions: –Which director has had the most female actors working for him? –In which years films have been shot that starred actors born between 1926 and 1935? Such questions can be encoded in a language know as “structured query language” or SQL. All relational database vendors implement a dialect of SQL.

mySQL They are a very successful, open-source vendor of SQL software. Their product is basically freely available. We will learn the mySQL dialect of SQL.

using mySQL mySQL is installed on wotan. Normally this involves logging into wotan and issuing commands to a character interface. The command would be –mysql -u user -p

create database This is a mySQL command to create a new database. Example –create database newbase; creates a database newbase

GRANT This is a command to create users and give them privileges. A simplified general syntax is GRANT privileges [columns] ON item TO user_name [IDENTIFIED BY 'password''] [WITH GRANT OPTION] If you use WITH GRANT OPTION, you allow the user to grant other users the privileges that you have given to her.

user privilegesI SELECTallows users to select (read) records from tables. INSERTallows users to insert new rows into tables. UPDATEallows users to change values in existing table rows. DELETEallows users to delete table rows. INDEX allows user to index tables

user privilegesII ALTERallows users to change the structure of the database. –adding columns –renaming columns or tables –changing the data types of tables DROP allows users databases or tables.

user privilegesIII CREATEallows users to create new databases or tables. If a specific table or database is mentioned in the GRANT statement, users can only create that database or table, which will mean that they have to drop it first. USAGEallows users nothing. This is a useful point to start with if you just want to create a user.

REVOKE This is the opposite of GRANT.

current setup As the super user, I did create database user_name; GRANT * ON user_name TO user_name IDENTIFIED BY 'secret_word'' WITH GRANT OPTION; Here –user_name is your wotan user name –secret_word is your secret word –* means all rights

create a web user You do not want to give the same access rights to people coming in from the web as you have. You do not want to do this. You personally have too many privileges. I have yet to find out how you can create a web user by yourself.

creating tables before you do it, set up some examples on a sheet of paper. Here is an example CREATE TABLE customers (custumer_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(50) NOT NULL, ADDRESS CHAR(100) not NULL, CHAR(40), STATE char(2) not NULL);

column data types TINYINT can hold a number between -128 and 127 or between 0 to 255. BIT or BOOL are synonyms for the TINYINT. SMALLINT can hold a number between and or 0 and INT can hold a number between -2**31 and 2**31-1 or between 0 and 2**32-1. INTEGER is a synonym for INT. BIGINT can hold a number between -2**63 and 2**61-1 or between 0 and 2**64-1.

column data types: float FLOAT is a floating number on 4 bytes DOUBLE is a floating number on 8 bytes

column data types: dates DATE is a day from to TIME is a time from -838:59:59 to 838:59:59 DATETIME is a data and time, usually displayed as YYYY-MM-DD HH:MM:SS TIMESTAMP is the number of seconds since at 0 hours. This number may run out in 2037.

field options PRIMARY KEY says that this column is a the primary key. There can be only one such column. Values in the column must be unique. AUTO_INCREMENT can be used on columns that contain integer values.

functions The PHP function reference is available on its web site It shows the impressive array of functions within PHP. But one of the strengths of PHP is that you can create your own functions as you please. If you recreate one of the built-in functions, your own function will have no effect.

example Stephanie Rubino was an English teacher and objects to sentences like You have ordered 1 bottles of Grosswald Pils. Let us define a function rubino_print(). It will take three arguments –a number to check for plural or singular –a word for the singular –a word for the plural

function and parameters use the keyword "function" and declare your parameters, as in: function rubino_print ($number, $singular,$plural) { if($number == 1) { print "one $singular"; } else { print "$number $plural"; }

default arguments Sometimes you want to allow a function to be called without giving all its arguments. You can do this by declaring a default value. For the previous example function thomas_need($thing='beer') { print "I need $thing\n"; } thomas_need(); // prints: I need beer; thomas_need('sleep'); // prints: I need sleep;

rubino_print using common plurals function rubino_print ($num, $sing,$plur=1) { if($num == 1) { print "one $sing"; } elseif($plur ==1) { print "$num $sing"."s"; } else { print "$num $plur"; }

return value Up until now we have just looked at the effect of a function. return is a special command that return a value. When return is used, the function is left.

rubino_print with return function rubino_print ($number, $singular,$plural) { if($number == 1) { return "one $singular"; } return "$number $plural"; } $order=rubino_print(2,"beer","beers"); print "you ordered $order\n"; // prints: you ordered 2 beers.

visibility of variables variables used inside a function are not visible from the outside. Example $beer="Karlsberg"; function yankeefy ($name='Sam Adams') { $beer=$name; } yankeefy(); print $beer;// prints: Karlsberg the variable inside the function is something different than the variables outside.

accessing global variables. There are two ways to change a global variable, i.e. one that is defined in the main script. One is just to call it as $GLOBAL['name'] where name is the name of the global variable. function yankeefy ($name="Sam Adams") { $GLOBAL['beer']="name"; }

brewer_quiz.php: introduction <?php $brewers=array('Großwald Brauerei','Homburger Brauhaus', 'Karlsberg Brauerei','Ponter Hausbrauerei', 'Saarfürst Merziger Brauhaus','Mettlacher Abtei-Bräu','Körpricher Landbräu','Brauerei G.A. Bruch','Neufang Brauerei','Zum Stiefel'); $form_top=" \n"; $form_submit=' '."\n"; $form_end=' ';

brewer_quiz.php: form building function build_form($answer,$comment) { print " Take the Saarland brewery challenge \n"; print $GLOBALS['form_top']; print " "; print $GLOBALS['form_submit']; print $GLOBALS['submit_check']; print $GLOBALS['form_end']; print $comment; }

brewer_quiz.php: form processing function process_form($answer,$brewers) { $r[]=$answer; foreach($brewers as $brew) { if($answer == "$brew") { $r[]=' Congradulation! This is correct! '; return $r; } $r[]=' This is a bad answer, try again! '; return $r; }

brewer_quiz.php main part if($_GET['submitted']) { $from_form=process_form($_GET['guess'],$brewer s); } build_form($from_form[0],$from_form[1]) ; ?>

working with many source files Many times it is useful to split a PHP script into several files. PHP has two mechanisms. require(file) requires the to be included. If the file is not there, PHP exits with an error. include(file) includes the file.

require() and include() Both assume that you leave PHP. Thus within your included file you can write simple HTML. If you want to include PHP in your included file, you have to surround it by, just like in a PHP script. Here is an example to use include to build the basic web page.

bottom.html <i mg style="border: 0pt" src=" alt="Valid XHTML 1.0!" height="31" width="88" />

validated.php <?php $title="my basic page\n"; include("top.html"); print " hello, world "; include("bottom.html"); ?>

trouble $title in the top.html is not understood as the title. It reads as $title, which means "idiot" for your web user. Even if you replace $title with $title is empty. The definition from the outer file is not seen in the included file. So you have to split into three files, and print the title in the main file. I leave that to you to figure out.

Thank you for your attention!