Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Databases for Web applications Making a table of SQL queries. PHP and other DBMSs. Rights. Left Join, etc. Homework: Make posting on Open Source.

Similar presentations


Presentation on theme: "Creating Databases for Web applications Making a table of SQL queries. PHP and other DBMSs. Rights. Left Join, etc. Homework: Make posting on Open Source."— Presentation transcript:

1 Creating Databases for Web applications Making a table of SQL queries. PHP and other DBMSs. Rights. Left Join, etc. Homework: Make posting on Open Source versus Proprietary. Keep working on projects. Happy thanksgiving.

2 What are tables in given database Show table names <?php require("jeanine\quizphp\opendbq.php"); $query="show tables"; $rs=mysql_db_query($DBname, $query, $link); ?> Table names <? while ($row=mysql_fetch_array($rs)){ print(" "); print($row[0]); print(" "); } print(" "); ?>

3 result Table names catalog customers history ordereditems orders players questions

4 Show table names and field names <?php require("jeanine\quizphp\opendbq.php"); $query="show tables"; $rs=mysql_db_query($DBname, $query, $link); ?> Table names <? $i = 0; while ($row=mysql_fetch_array($rs)){ print(" "); $tablenames[$i] = $row[0]; $i++; print($row[0]); print(" "); } print(" ");

5 for ($j=0;$j<$i;$j++) { $query = "describe ".$tablenames[$j]; print (" ". $tablenames[$j]. " table \n "); print (" Field Type Null Key \n "); $rt=mysql_db_query($DBname,$query,$link); while ($fi=mysql_fetch_array($rt)) { print (" ". $fi['Field']. " \n "); print (" ".$fi['Type']. " \n "); print (" ".$fi['Null']. " \n "); print (" ".$fi['Key']. " \n "); print (" "); } print (" "); } ?>

6

7 Table of queries If you have a large set of fixed SQL queries, you may make a new table: iddescriptiontext 1final diagnosis when presenting signs of appendicitis Select final.diagnosis from final, initial where initial.temp > 100 AND initial.pain = 'left' AND final.caseno = initial.caseno 2initial potential ulcer cases Select * from initial where initial.pain = 'sharp' AND initial.temp < 100 ….

8 Present to user Pick selection: description final diagnosis when presenting signs of appendicitis initial potential ulcer cases Don't show the user the messy SQL

9 Produce responses Make the query the SQL corresponding to the user's choice. Display recordset in a table –Now, need generalized code that creates headings for tables and extracts names of fields 'on the fly' based on information in recordset. php: –mysql_fetch_field –mysql_fetch_array

10 Current Favorites <?php require("openfirstdb.php"); $query="Select * from favorites"; $result=mysql_db_query($DBname, $query, $link); $fieldnames= Array(); print (" "); $nf = mysql_num_fields($result); for ($i=0; $i<$nf;$i++) { $fieldobj= mysql_fetch_field($result); $fieldnames[$i]=$fieldobj->name; print (" ".$fieldnames[$i]." "); } print (" \n"); while ($row=mysql_fetch_array($result)) { print (" "); for ($i=0; $i<$nf; $i++) { print (" ".$row[$fieldnames[$i]]." "); } print(" "); } mysql_close($link); ?> first for loop to set up headers Second for loop, in while loop, to extract field data.

11

12 Note If you do [ever] show field names to your customers/clients/players/…, you need to make them longer/better/etc.

13 MySQL Rights Possible to limit rights to specific users. –specific table or whole database –SELECT, INSERT, DELETE, UPDATE, DROP, CREATE, ALTER NOTE: I don't know if your rights include right to use GRANT! Limiting rights is to prevent unintentional errors as much as / more than not trusting certain people. Your php code is main line of protection.

14 Left Join, etc. Searching for something that isn't there. –Left Join –NOT EXISTS. You can create (on the fly) a new table and check if it has any rows. –See http://explainextended.com/2009/09/18/not-in- vs-not-exists-vs-left-join-is-null-mysql/ http://explainextended.com/2009/09/18/not-in- vs-not-exists-vs-left-join-is-null-mysql/

15 php: checking for value Using isset($_GET['guess']) is better than using $guess = @$_GET['guess']; if ($guess != null) { }

16 php: strpos Check if string is present in another string $n = strpos($answer,"SUNY"); if ($n>-1) { } Alternative to regular expression

17 php: explode Breaks up string into an array if $listofstuff is "orange,apple,peach" $list = explode(",",$listofstuff); produces $list = ["orange","apple","peach"];

18 Database administrator technical: working with software, including maintaining security, performance. Keeping aware of changes in products, new products. administrative: working with technical staff AND other staff specific business: knowing and keeping up-to-date with knowledge of this business.

19 Internationalization & Localization How to make the php MySQL application work in different places character sets (includes symbols, encodings for symbols, collations (ordering rules) error messages (MySQL). Presumably your php code does error handling, also. time zone way to express dates See SET and SHOW commands

20 Homework Keep working on projects Make posting on Open Source: what it means to you and what you think about it. –THINK! why would a company use Open source and why not what does it mean for information technology worker


Download ppt "Creating Databases for Web applications Making a table of SQL queries. PHP and other DBMSs. Rights. Left Join, etc. Homework: Make posting on Open Source."

Similar presentations


Ads by Google