CCT395, Week 7 SQL with PHP This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit

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 PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
INTERNET APPLICATION DEVELOPMENT For More visit:
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.
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.
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.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Intro to LAMP Programming Presented for CIS Faculty at SAC by Dan Zollars.
INTERNET APPLICATION DEVELOPMENT Practical on Sessions.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Lecture 10 – MYSQL and PHP (Part 2)
Technology & Management Club Development Software Overview.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
PHP with MySQL 1.
Website Development with PHP and MySQL Saving Data.
MySQL Database Connection
Creating PHPs to Insert, Update, and Delete Data CS 320.
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
Intro to LAMP Programming Presented for SAT Linux Users' Group by Dan Zollars.
Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
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.
Accessing mySQL relational database. MySQL database.  Today, we will attempt and open a connection to the MySQL server.  We need to specify the database.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
PHP with MYSQL Please use speaker notes for additional information!
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 8 – Review Reference:
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 8 Databases and Documents This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license,
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 4 Database Design and ER Modeling This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT395, Week 12 Storage, Grid Computing, Review This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 11 Review, Permissions Physical Storage and Performance This presentation is licensed under Creative Commons Attribution License, v. 3.0.
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
CCT395, Week 2 Introduction to SQL Yuri Takhteyev September 15, 2010
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 5 Translating ER into Relations; Normalization This presentation is licensed under Creative Commons Attribution License, v To view a.
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
PHP (Session 2) INFO 257 Supplement.
Remote hosts and web servers
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Review Databases and Objects
Special Topics in CCIT: Databases
CCT1343, Week 2 Single-Table SQL Yuri Takhteyev University of Toronto
Applying the OSS Model to Other Domains
Database Design and Implementation
Data Modeling and Database Design
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Database Design and Implementation
PHP: Combo box FdSc Module 109 Server side scripting and
Web Programming– UFCFB Lecture
PHP Forms and Databases.
Database Access with PHP and MySQL
Presentation transcript:

CCT395, Week 7 SQL with PHP This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from Yuri Takhteyev University of Toronto October 20, 2010

The Project ● Groups of up to 3 students ● Same amount of work regardless of size ● 6-12 entities ● Roughly the same complexity as Madame Z’s database ● A simple PHP front-end ● Proposal due on November 3 ● A list of group members ● A functional specification (be clear what is out of scope) ● An ER diagram ● Who is going to do what and when

Facebook runs on MySQL

“yoda”, “alice”, “pumpkins” “alice”, “pumpkins” Telnet (1969) ok “mysql -p” “enter password:”

“yoda”, “alice”, “pumpkins” “alice”, “pumpkins” FTP (1971) ok “ftp>” “get /path/to/monkeys.txt” monkeys.txt the file is saved locally

“yoda”, “/path/to/monkeys.txt” “get /path/to/monkeys.txt” Anonymous FTP monkeys.txt the file is saved locally ftp://yoda/path/to/monkeys.tx t

“yoda”, “/path/to/monkeys.html” “GET /path/to/monkeys.html” HTTP (1991) monkeys.html l monkeys.htm is displayedl

HTML CCT395H5F: Databases (Special Topics in CCIT) CCT395H5F, University of Toronto, Mississauga...

“yoda”, “/path/to/monkeys.cgi” “GET /path/to/monkeys.cgi” CGI html output of monkeys.cgi monkeys.cgi contains code, but returns HTML html output is displayedl

PHP = HTML + Code

HTML 17 monkeys are happy. 17 monkeys are happy.

PHP monkeys are happy. 17 monkeys are happy. 17 monkeys are happy.

Variables <?php $count=17; echo $count; ?> monkeys are happy. 17 monkeys are happy.

Concatenation <?php $mood="happy"; $count=17; echo $count. " monkeys are ". $mood; ?> 17 monkeys are happy.

Concatenation <?php $mood="happy"; $count=17; echo $count. " monkeys are ". $mood; ?>

A Demo protocol server address path user name

Always the Same? Parameters - additional data from the user Database - information that we store

Database <?php $connection = mysql_connect("localhost", "kenobio", "th3f0rc3"); mysql_select_db("kenobio", $connection); $query = "select count(*) from monkeys where mood='H'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row['count(*)']; echo " monkeys are happy."; ?>

Iterating <?php $connection = mysql_connect("localhost", "kenobio", "th3f0rc3"); mysql_select_db("kenobio", $connection); $query = "select * from monkeys where mood='H'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo $row['monkey_id']. " "; } ?>

Counting <?php $connection = mysql_connect("localhost", "kenobio", "th3f0rc3"); mysql_select_db("kenobio", $connection); $query = "select * from monkeys where mood='H'"; $result = mysql_query($query); $count = 0; while($row = mysql_fetch_array($result)) { echo $row['monkey_id']. " "; $count = $count + 1; } echo "Count: ". $count. " monkeys are happy."; ?>

Conditionals <?php $connection = mysql_connect("localhost", "kenobio", "th3f0rc3"); if (!$connection) { die('Could not connect to the database: '. mysql_error()); } mysql_select_db("kenobio", $connection); $query = "select * from monkeys where mood='H'"; $result = mysql_query($query); $count = 0;...

Conditionals mysql_select_db("kenobio", $connection); $query = "select * from monkeys"; $result = mysql_query($query); $count = 0; while($row = mysql_fetch_array($result)) { if ($row['mood']=="H") { echo $row['monkey_id']. " "; $count = $count + 1; } echo "Count: ". $count. " monkeys are happy.";

Conditionals mysql_select_db("kenobio", $connection); $query = "select * from monkeys"; $result = mysql_query($query); $count = 0; while($row = mysql_fetch_array($result)) { echo $row['name']. ": ". $row['mood']. " "; if ($row['mood']=="H") { $count = $count + 1; } echo "Count: ". $count. " monkeys are happy.";

Conditionals mysql_select_db("kenobio", $connection); $query = "select * from monkeys"; $result = mysql_query($query); $count = 0; while($row = mysql_fetch_array($result)) { $mood = $row['mood']; if ($mood=="H") { echo " :) "; $count = $count + 1; } else { echo " :( "; } echo $row['name']. " "; } echo "Count: ". $count. " monkeys are happy.";

Parameters - additional data from the user Database - information that we store

GET Parameters Monkeys with mood "<?php echo $_GET["mood"]; ?>": Monkeys with mood "H": Monkeys with mood "H":

GET Parameters

GET Parameters $desired_mood = $_GET["mood"]; echo "Monkeys with mood '". $desired_mood. "': "; $query = "select * from monkeys"; $result = mysql_query($query); $count = 0; while($row = mysql_fetch_array($result)) { if ($row['mood']==$desired_mood) { $count = $count + 1; echo $row['name']. " "; } echo "Count: ". $count;

Dynamic SQL $desired_mood = $_GET["mood"]; echo "Monkeys with mood '". $desired_mood. "': "; $query = "select * from monkeys where mood='". $desired_mood. "'"; $result = mysql_query($query); $count = 0; while($row = mysql_fetch_array($result)) { $count = $count + 1; echo $row['name']. " "; } echo "Count: ". $count; Don’t do this!

Dynamic SQL $desired_mood = $_GET["mood"]; if ($desired_mood!="H" and $desired_mood!="S") { die ("Illegal mood"); } echo "Monkeys with mood '". $desired_mood. "': "; $query = "select * from monkeys where mood='". $desired_mood. "'"; $result = mysql_query($query); $count = 0; while($row = mysql_fetch_array($result)) { $count = $count + 1; echo $row['name']. " "; } echo "Count: ". $count;

HTML Forms Please select mood:

HTML Forms Please select mood: happy sad

POST Parameters monkeys_6.php: $desired_mood = $_POST["mood"]; monkey_form_3.html: Please select mood: happy sad

Questions?