INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.

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

What is MySQL? MySQL is a relational database management system (A relational database stores data in separate tables rather than putting all the data.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective,
Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop small-group/
Create an online booking system (login/registration)
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
SQL HW1 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
CIS166AE : PHP Web Scripting Rob Loy. Tonight’s Agenda Housekeeping items Housekeeping items PHP basics PHP basics Student connection to server Student.
Introduction Copyright © Software Carpentry This work is licensed under the Creative Commons Attribution License See
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 4: Writing programs.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Database Security DAC MAC Application Servers Web Encryption Users/Roles Stored Procedures, Views.
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
Introduction to Database Programming with Python Gary Stewart
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.
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.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
Welcome to INF1343! Database Modeling and Database Design This presentation is licensed under Creative Commons Attribution License, v To view a copy.
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.
PHP AND SQL SERVER: CONNECTION IST 210: Organization of Data IST210 1.
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.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT1343, Week 3 SQL Queries Using Multiple Tables This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
INF1343, Week 6 Implementing a Database with SQL This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
Database Design and Implementation
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.
INF1343, Week 4 Database Design and ER Modeling This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 7 SQL with PHP This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
2nd year Computer Science & Engineer
FIND THE VOLUME: 5 in 8 in 4 in.
PDO Database Connections
PHP (Session 2) INFO 257 Supplement.
Licenses and Interpreted Languages for DHTC Thursday morning, 10:45 am
Review Databases and Objects
Special Topics in CCIT: Databases
CCT1343, Week 2 Single-Table SQL Yuri Takhteyev University of Toronto
Relational database and SQL MySQL LAMP SQL queries
Database application MySQL Database and PhpMyAdmin
mysql and mysql workbench
Database Design and Implementation
Data Modeling and Database Design
Conditions System Update and Discussion
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Database Design and Implementation
PDO Database Connections
BASIC PHP and MYSQL Edward S. Flores.
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Learning to Program in Python
PDO Database Connections
Working with Big Data in SQL
PDO Database Connections
Introduction to TouchDevelop
JavaScript.
MIS2502: Data Analytics MySQL and SQL Workbench
PHP: Database connection
Stata Basic Course Lab 2.
Presentation transcript:

INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto 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

Week 7 Embedded SQL

Facebook runs on MySQL

Alic e Bob application software database “persistent storage”

Computer Languages Domain Specific: Has a narrow purpose. Examples: SQL, HTML, Matlab. General Purpose: Can be used for anything. Examples: Python, Java, PHP.

Computer Languages Declarative: “Tell me what you want.” Examples: SQL, HTML, Matlab. Procedural: “Tell me what you want me to do.” Examples: Python, Java, PHP.

Python print "Hello, World!" greeting = "Hello, World!" print greeting

Python on R2 via SSH On Windows: use PuTTY Hostname: r2.ischool.utoronto.ca Username: same as for MySQL WB Password: same as for MySQL WB On OSX/Unix: use Terminal App ssh ssh Once connected, type “python”.

A Few Tips Ctrl+D to quit. Ctrl+L to clear screen. Up arrow to bring back earlier commands.

Trying Some Python print "Hello, World!" greeting = "Hello, World!" print greeting x = 2 print x x = x + 2 print x

Adding Strings greeting = "Hello, " print greeting + "Bob" + "!" name = "Alice" print greeting + name + "!" name = "Ze" print greeting + name + "!"

Lists names = ["Alice", "Bob", "Ze"] print names[1] greeting = "Hello, " print greeting + names[1] i = 2 print greeting + names[i]

Oops i = 4 print greeting + names[i]

Functions print len(names) print max(1,22,19,2)

Conditions names = ["Alice", "Bob", "Ze"] i = 2 if i < len(names): print greeting + names[i] else: print "i is too large!" 4 spaces. Do not use tabs.

A Programming Editor On Windows: Notepad++ On OSX: TextWranger

Getting the Files to R2 On Windows: WinSCP On OSX: Cyberduck Same hostname, username, password as for SSH.

Executing a Python File python «filename» For instance: python greetings.py

Loops names = ["Alice", "Bob", "Ze"] for name in names: print greeting + name 4 spaces. Do not use tabs.

Combining names = ["Alice", "Bob", "Ze"] for name in names: if name=="Ze": print "Oi, Ze" else: print greeting+name 4 spaces. Do not use tabs.

Using the DB from padawan import * connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) print get_row_count() Padawan gives you a subset of the DB functionality. For more options you can try Python’s module MySQLdb (this is what Padawan uses behind the scenes).

Getting Values connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) print get_row_count() rows = fetch_all_rows() row = rows[0] print row # or: row = get_row(0) print row[2] print get_row_value(row, "species")

Loops connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) print get_row_count() rows = fetch_all_rows() for row in rows : print get_row_value(row, "species")

Longer Loops connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) print get_row_count() for row in fetch_all_rows() : name = get_row_value(row, "name") world = get_row_value(row, "homeworld") print greeting + name, world print "done!"

Longer Loops connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) print get_row_count() for row in fetch_all_rows() : name = get_row_value(row, "name") world = get_row_value(row, "homeworld") print greeting + name + world print "done!" TypeError: cannot concatenate 'str' and 'NoneType' objects

Yet Longer Loops connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) print get_row_count() for row in fetch_all_rows(): name = get_row_value(row, "name") world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print greeting+name+" from "+world

Templates template = "Greetings, %s from %s!" query = "select * from persona" execute_query(query) for row in fetch_all_rows(): name = get_row_value(row, "name") world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print fill_template(template, name, world) (Alternatively, use Python’s “%” operator.)

Fancier Queries template = "Greetings, %s from %s!" query = """select * from persona where name="Jabba";""" execute_query(query) for row in fetch_all_rows(): name = get_row_value(row, "name") world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print fill_template(template, name, world)

Query Templates template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" query = fill_template(query_template, "Jabba") execute_query(query) for row in fetch_all_rows(): world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print fill_template(template, name, world)

Interactivity template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") query = fill_template(query_template, name) execute_query(query) for row in fetch_all_rows(): world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print fill_template(template, name, world) (We stopped here in class.)

Or Rather template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") query = fill_template(query_template, name) execute_query(query) if get_row_count() > 0 : rows = fetch_all_rows() row = rows[0] world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print fill_template(template, name, world) else : print "No such user!"

Worlds as Passwords template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") world = raw_input("Where are you from? ") query = fill_template(query_template, name) execute_query(query) if get_row_count() > 0 : rows = fetch_all_rows() row = rows[0] real_world = get_row_value(row, "homeworld") if world==real_world: print fill_template(template, name, world) else: print "Access denied!" else : print "No such user!"

Worlds as Passwords template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") world = raw_input("Where are you from? ") query = fill_template(query_template, name) execute_query(query) if get_row_count() > 0 : rows = fetch_all_rows() row = rows[0] real_world = get_row_value(row, "homeworld") if world==real_world: print fill_template(template, name, world) else : print "Access denied!"

Worlds as Passwords template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s" and world="%s";""" name = raw_input("What is your name? ") world = raw_input("Where are you from? ") query = fill_template(query_template, name, world) execute_query(query) if get_row_count() > 0 : print fill_template(template, name, world) else : print "Access denied!"

What about Inserts? from padawan import * connect_to_db("okenobi", "okenobi") query_template = """insert into persona(name) values ("%s");""" name = raw_input("What is your name? ") query = fill_template(query_template, name) execute_query(query) print "You are now in our database!"

Questions?