Presentation is loading. Please wait.

Presentation is loading. Please wait.

CCT395, Week 8 Databases and Documents This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license,

Similar presentations


Presentation on theme: "CCT395, Week 8 Databases and Documents This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license,"— Presentation transcript:

1 CCT395, Week 8 Databases and Documents This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from http://everaldo.com/crystal/. Yuri Takhteyev University of Toronto October 27, 2010

2 Assignment 2

3 comment ------------------- text time item ------------------- time type access filename text user ------------------- email 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

4 to be continued

5 The Project ● Groups of up to 3 students ● Same amount of work regardless of size ● Email me if you cannot find a group

6 The Project ● 5-10 entities / tables ● A little simpler than Madame Z’s database ● A simple PHP front-end

7 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

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

9 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."; ?>

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

11 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;

12 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!

13 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;

14 HTML Forms Please select mood:

15 Menagerie Web Get the files: http://takhteyev.org/courses/10F/cct395/menagerie-web.zip 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

16 Menagerie Web Put them in your ~/public_html/: Mac: cd menagerie-web/* scp * kenobio@yoda.ischool.utoronto.ca:~/public_html/ Windows: use WinSCP: http://winscp.net/ Set permissions (on the server!): cd ~/public_html ls chmod a+r *.html chmod a+rx *.php See if it's working: http://yoda.ischool.utoronto.ca/~kenobio/pet_form.html

17 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!

18 PHPMyAdmin http://yoda.ischool.utoronto.ca/phpmyadmin/

19 Documents Onto this week's topic:

20 http://upload.wikimedia.org/wikipedia/commons/5/51/BarackObamaCertificationOfLiveBirthHawaii.j pg

21

22 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

23 http://commons.wikimedia.org/wiki/File:Invoice- Esso.jpg

24 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.

25 AliceBob invoice payment order

26 AliceBob payment invoice (HTML) order

27 AliceBob

28 AliceBob invoice payment order machine-readable documents

29 9834562 2003-03-14 Bills Microdevices Spring St. 413 Elgin 60123 IL Joes Office Supply Lakeshore Dr 32 W. Chicago 60022 IL XML http://docs.oasis-open.org/ubl/cd-UBL-1.0/xml/office/UBL-Invoice-1.0-Office- Example.xml

30 479.50 527.45 1 5 12.50 Pencils, box #2 red 32145-12 2.50... XML

31 1 5 12.50 Pencils, box #2 red 32145-12 2.50 XML Anatomy

32 1 5 12.50 Pencils, box #2 red 32145-12 2.50 XML Anatomy

33 Validation Syntactic: form 12.50</Amount Semantic: meaning Male

34 9834562 2003-03-14 20031234-1 154135798 2003-02-02 Bills Microdevices Spring St. 413 Elgin 60123 IL Namespaces

35 XML and RDBMS Externalization: export, import, messaging Internal use: XML storage and retrieval (less common for now)

36 AliceBob application software (e.g., using PHP) database HTML

37 AliceBob application software (e.g., using PHP) database HTTP request HTTP request HTML SQL

38 AliceBob application software (e.g., using PHP) database HTTP request HTTP request HTML SQL

39 AliceBob application software (e.g., using PHP) database HTTP request HTTP request HTML XML SQL

40 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”

41 Examples Twitter: http://twitter.com/public_timeline vs. http://api.twitter.com/1/statuses/public_timeline.xml

42

43

44

45

46

47 Examples Yahoo! Geocoding API: http://maps.yahoo.com/#&q1=3359+Mississauga+Rd+N. %2C+Mississauga%2C+ON vs. http://local.yahooapis.com/MapsService/V1/geocode? appid=YD- 9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA-- &street=3359+Mississauga+Rd+N&city=Mississauga &state=ON&country=Canada

48

49 43.546733 - 79.665611 3359 Mississauga Rd Mississauga ON L5L CA

50 <Result precision="address" warning="The exact location could not be found..."> 43.546733 -79.665611 3359 Mississauga Rd Mississauga ON L5L CA

51 Examples Geonames Web Service http://ws.geonames.org/wikipediaBoundingBox? north=45&south=42&east=-78&west=-82

52 en Toronto Toronto (, local pronunciation ) is the largest city in Canada[http://wwp.canada-ca.net/ Canada], Greenwich Mean Time. Retrieved on 2007-07-08. and is the provincial capital of Ontario. It is located on the northwestern shore of Lake Ontario.[http://www.city-data.com/world- cities/Toronto.html Toronto, Ontario, Canada, North America] Retrieved on 2007-07-08. With over 2 (...) 0 43.65 -79.3833 http://en.wikipedia.org/wiki/Toronto http://www.geonames.org/img/wikipedia/470 00/thumb-46020-100.jpg

53 Alternatives JSON http://ws.geonames.org/wikipediaBoundingBoxJSON? formatted=true&north=45&south=42 &east=-78&west=-82

54 {"geonames": [ { "summary": "Toronto (, local pronunciation ) is the largest city in Canada[http://wwp.canada-ca.net/ Canada], Greenwich Mean Time. Retrieved on 2007-07-08. and is the provincial capital of Ontario. It is located on the northwestern shore of Lake Ontario.[http://www.city-data.com/world- cities/Toronto.html Toronto, Ontario, Canada, North America] Retrieved on 2007-07-08. With over 2 (...)", "title": "Toronto", "wikipediaUrl": "en.wikipedia.org/wiki/Toronto", "elevation": 0, "countryCode": " ", "lng": -79.3833333333333, "feature": "", "thumbnailImg": "http://www.geonames.org/img/wikipedia/47000/thumb- 46020-100.jpg", "lang": "en", "lat": 43.65, "population": 0 },

55 Examples Yahoo! Geocoding API: http://maps.yahoo.com/#&q1=3359+Mississauga+Rd+N. %2C+Mississauga%2C+ON vs. http://local.yahooapis.com/MapsService/V1/geocode? appid=YD- 9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA-- &street=3359+Mississauga+Rd+N&city=Mississauga &state=ON&country=Canada

56 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:27 +0000 2010","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":"http:\/\/a1.twim g.com\/profile_background_images\/159886578\/tumblr_l 8hz3wJ5lK1qb7u0po1_400.gif","profile_text_color":"eb1 725","url":"http:\/\/www.fotolog.com.br\/livinhacontr eras","verified":false,"profile_background_tile":true,"follow_request_sent":null,"lang":"en","created_at": "Fri Jun 26 03:54:16 +0000 2009","profile_link_color":"0fc3ff","location":"Brasi l","protected":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1143256104\/P1060283_- _C_pia_normal.JPG",

57 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:27 +0000 2010","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":"http:\/\/a1.twimg.com\/profile_background_image s\/159886578\/tumblr_l8hz3wJ5lK1qb7u0po1_400.gif","profile_text_col or":"eb1725","url":"http:\/\/www.fotolog.com.br\/livinhacontreras", "verified":false,"profile_background_tile":true,"follow_request_sen t":null,"lang":"en","created_at":"Fri Jun 26 03:54:16 +0000 2009","profile_link_color":"0fc3ff","location":"Brasil","protected" :false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/ 1143256104\/P1060283_-_C_pia_normal.JPG",

58 More PHPMyAdmin

59 1 H Betsy 5 2 S Boris 2 4 H Miss M 9 XML

60 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

61 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.)

62 Questions?


Download ppt "CCT395, Week 8 Databases and Documents This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license,"

Similar presentations


Ads by Google