CCT395, Week 8 Databases and Documents 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 27, 2010
Assignment 2
comment text time item time type access filename text user password name age gender user posted item comment refers to item user posted comment user1 designated as friend user2 user1 is confirmed friend of user2
to be continued
The Project ● Groups of up to 3 students ● Same amount of work regardless of size ● me if you cannot find a group
The Project ● 5-10 entities / tables ● A little simpler than Madame Z’s database ● A simple PHP front-end
The Project ● 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
PHP <?php $count=17; echo $count; ?> monkeys are happy. 17 monkeys are happy.
PHP and MySQL <?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."; ?>
GET Parameters Monkeys with mood "<?php echo $_GET["mood"]; ?>": Monkeys with mood "H": Monkeys with mood "H":
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:
Menagerie Web Get the files: Edit the files: Change the username and the password, Do not make any other changes yet. Software for Editing: A “code editor” with syntax highlighting Notepad++ for Windows TextWrangler for Mac Gedit for Linux
Menagerie Web Put them in your ~/public_html/: Mac: cd menagerie-web/* scp * Windows: use WinSCP: Set permissions (on the server!): cd ~/public_html ls chmod a+r *.html chmod a+rx *.php See if it's working:
Troubleshooting Check that you: - changed the username and password - made no other changes to the files - copied the files (check that they are there using “ls”!) - set the permissions Once you start making changes: - make them in small steps - keep the previous version that you know works!
PHPMyAdmin
Documents Onto this week's topic:
pg
name: Barack Hussein Obama II date_of_birth: August 4, 1961 sex: male location: Honolulu mother: Stanley Ann Dunham father: Barack Hussein Obama hour_of_birth: 7:24 pm... Digital
Esso.jpg
Full Text Search Matching sub-strings Can be done with LIKE Bag-of-words search Like doing LIKE for every term – very slow without a proper index! Natural language search Stop words (“the”, “of”, “to”, “end”) Stemming (“monkey” vs “monkeys”) Synonyms (“monkey” vs “simian” vs “Affe”) Ranking Repeated used many times, rare words Can be useful. SQL support is coming.
AliceBob invoice payment order
AliceBob payment invoice (HTML) order
AliceBob
AliceBob invoice payment order machine-readable documents
Bills Microdevices Spring St. 413 Elgin IL Joes Office Supply Lakeshore Dr 32 W. Chicago IL XML Example.xml
Pencils, box #2 red XML
Pencils, box #2 red XML Anatomy
Pencils, box #2 red XML Anatomy
Validation Syntactic: form 12.50</Amount Semantic: meaning Male
Bills Microdevices Spring St. 413 Elgin IL Namespaces
XML and RDBMS Externalization: export, import, messaging Internal use: XML storage and retrieval (less common for now)
AliceBob application software (e.g., using PHP) database HTML
AliceBob application software (e.g., using PHP) database HTTP request HTTP request HTML SQL
AliceBob application software (e.g., using PHP) database HTTP request HTTP request HTML SQL
AliceBob application software (e.g., using PHP) database HTTP request HTTP request HTML XML SQL
Bob application software (e.g., using PHP) database HTTP request HTTP request HTML XML SQL Alice Inc. “Web services”, “APIs”, “REST”, “Semantic web,” “Service-oriented architecture”
Examples Twitter: vs.
Examples Yahoo! Geocoding API: %2C+Mississauga%2C+ON vs. appid=YD- 9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA-- &street=3359+Mississauga+Rd+N&city=Mississauga &state=ON&country=Canada
Mississauga Rd Mississauga ON L5L CA
<Result precision="address" warning="The exact location could not be found..."> Mississauga Rd Mississauga ON L5L CA
Examples Geonames Web Service north=45&south=42&east=-78&west=-82
en Toronto Toronto (, local pronunciation ) is the largest city in Canada[ Canada], Greenwich Mean Time. Retrieved on and is the provincial capital of Ontario. It is located on the northwestern shore of Lake Ontario.[ cities/Toronto.html Toronto, Ontario, Canada, North America] Retrieved on With over 2 (...) /thumb jpg
Alternatives JSON formatted=true&north=45&south=42 &east=-78&west=-82
{"geonames": [ { "summary": "Toronto (, local pronunciation ) is the largest city in Canada[ Canada], Greenwich Mean Time. Retrieved on and is the provincial capital of Ontario. It is located on the northwestern shore of Lake Ontario.[ cities/Toronto.html Toronto, Ontario, Canada, North America] Retrieved on With over 2 (...)", "title": "Toronto", "wikipediaUrl": "en.wikipedia.org/wiki/Toronto", "elevation": 0, "countryCode": " ", "lng": , "feature": "", "thumbnailImg": " jpg", "lang": "en", "lat": 43.65, "population": 0 },
Examples Yahoo! Geocoding API: %2C+Mississauga%2C+ON vs. appid=YD- 9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA-- &street=3359+Mississauga+Rd+N&city=Mississauga &state=ON&country=Canada
JSON [{"place":null,"geo":null,"truncated":false,"in_reply _to_status_id_str":null,"in_reply_to_status_id":null, "favorited":false,"in_reply_to_user_id_str":null,"sou rce":"web","contributors":null,"in_reply_to_screen_na me":null,"created_at":"Tue Oct 26 16:01: ","retweet_count":null,"in_reply_to_user_id":null,"user":{"statuses_count":1491,"description":"grafia","show_all_inline_media":false,"profile_use_backgroun d_image":true,"favourites_count":57,"followers_count" :124,"contributors_enabled":false,"notifications":nul l,"profile_background_color":"0c3bf5","geo_enabled":f alse,"profile_background_image_url":" g.com\/profile_background_images\/ \/tumblr_l 8hz3wJ5lK1qb7u0po1_400.gif","profile_text_color":"eb1 725","url":" eras","verified":false,"profile_background_tile":true,"follow_request_sent":null,"lang":"en","created_at": "Fri Jun 26 03:54: ","profile_link_color":"0fc3ff","location":"Brasi l","protected":false,"profile_image_url":" _C_pia_normal.JPG",
JSON [{"place":null,"geo":null,"truncated":false,"in_reply_to_status_id_ str":null,"in_reply_to_status_id":null,"favorited":false,"in_reply_ to_user_id_str":null,"source":"web","contributors":null,"in_reply_t o_screen_name":null,"created_at":"Tue Oct 26 16:01: ","retweet_count":null,"in_reply_to_user_id":null,"user":{"stat uses_count":1491,"description":"grafia","show_all_inline_media":fal se,"profile_use_background_image":true,"favourites_count":57,"follo wers_count":124,"contributors_enabled":false,"notifications":null," profile_background_color":"0c3bf5","geo_enabled":false,"profile_bac kground_image_url":" s\/ \/tumblr_l8hz3wJ5lK1qb7u0po1_400.gif","profile_text_col or":"eb1725","url":" "verified":false,"profile_background_tile":true,"follow_request_sen t":null,"lang":"en","created_at":"Fri Jun 26 03:54: ","profile_link_color":"0fc3ff","location":"Brasil","protected" :false,"profile_image_url":" \/P _-_C_pia_normal.JPG",
More PHPMyAdmin
1 H Betsy 5 2 S Boris 2 4 H Miss M 9 XML
1: monkey_id: 1 mood: H name: Betsy bananas_eaten: 5 2: monkey_id: 2 mood: S name: Boris bananas_eaten: 2 3: monkey_id: 4 mood: H name: Miss M bananas_eaten: 9 4: monkey_id: 5 mood: S name: Bob bananas_eaten: 2 YAML
SQL Support in RDBMS Direct XML export mysql -p --xml -e "use menagerie; select * from pet;" mysqldump --xml kenobio monkeys -p Direct XML import LOAD XML command in MySQL 6.0.3, but we are using 5.0. (Meanwhile, one can use a stored procedure.) Storing XML as a datatype Available in some systems, but not in MySQL currently. (Meanwhile, you can store XML a BLOB.)
Questions?