C20.0046- Database Management SystemsLecture #22.ppt
《C20.0046- Database Management SystemsLecture #22.ppt》由会员分享,可在线阅读,更多相关《C20.0046- Database Management SystemsLecture #22.ppt(31页珍藏版)》请在麦多课文档分享上搜索。
1、M.P. Johnson, DBMS, Stern/NYU, Spring 2005,1,C20.0046: Database Management Systems Lecture #22,M.P. Johnson Stern School of Business, NYU Spring, 2005,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,2,Homework,Project part 5 Topic: web interface + any remaining loose ends Up now Due: end of semesterWill
2、return proj3 today Remind me!,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,3,Agenda,Programming for SQL: DB-conn from web scripting languages DBI/DBDs in Perl, PHPTransactionsNext: Security Secrecy Integrity Availability Web issues,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,4,Goals: after this week,Af
3、ter Today: Have all the tools for building a DB-backed website in Perl or PHP (but will it be secure?),M.P. Johnson, DBMS, Stern/NYU, Spring 2005,5,Review: PHP,Image from http:/www.scit.wlv.ac.uk/jphb/cp3024/,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,6,Form example,On clicking Send, we go to the sa
4、me page, but with “name=99&sumbit=OK”,http:/pages.stern.nyu.edu/mjohnson/dbms/perl/input.cgi, Enter a number:,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,7,Review: dynamic webpages,First option: for each request: run program, produce whole page, send back CGI for each response, fill in the wholes and
5、 send back Embedded scripting PHP and others PHP = Personal Home Page or= PHP Hypertext Processor,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,8,hello.php,http:/pages.stern.nyu.edu/mjohnson/dbms/php/hello.phpQ: What the difference between and n?, Hello from PHPHere is the PHP part: n“; ? Thats it! ,M.
6、P. Johnson, DBMS, Stern/NYU, Spring 2005,9,hello2.php,Script errors, w/ and w/o display_errors on: http:/pages.stern.nyu.edu/mjohnson/dbms/perl/hello2.php http:/pages.stern.nyu.edu/mjohnson/dbms/php/hello2.phpLocal dir must contain .htaccess:Automatically load GET/POST params as vars http:/pages.ste
7、rn.nyu.edu/mjohnson/dbms/php/.htaccess,php_flag display_errors on php_flag register_globals on,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,10,More on PHP,Somewhat C-like, somewhat Perl-like Case-sensitive Strings: Concatenation op: . Single, double quotes similar to Perl Comments: # Unix shell-style
8、/* */ C-style / C+-style Output: echo(“hi there”); print(“hi there”); Cs printf,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,11,PHP vars,Similar to those of Perl, except no “my” http:/pages.stern.nyu.edu/mjohnson/dbms/php/math.php,“;print “Second number “ . $num2 . “;$total = $num1 + $num2;print “The
9、sum is “ . $total . “; ?,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,12,Combining PHP and HTML,http:/pages.stern.nyu.edu/mjohnson/dbms/php/combine.php,Iteration number ,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,13,PHP info,PHP does not have both string and number ops like Perl Number ops treat (numb
10、er) strings as numbers, regular strings as strings http:/pages.stern.nyu.edu/mjohnson/dbms/php/test.phpInfo function displays lots of server info: http:/pages.stern.nyu.edu/mjohnson/dbms/php/info.php,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,14,PHP & MySQL,PHP 5 has a DBI/JDBC-like interface Our ve
11、rsion/setup uses a proprietary lib:Open a connection and open our DB:Run query:,$db = mysql_connect(“mysql2.stern.nyu.edu:3306“, user, pass); mysql_select_db(“test“, $db);,$result = mysql_query($query,$db);,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,15,PHP & MySQL,Extract next row of data from state
12、ment, if available:What this means: myrow is an array that can then be accessed Other options, but this should suffice In general, to scroll through results, do:,$myrow = mysql_fetch_row($result),while ($myrow = mysql_fetch_row($result)# print rows data,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,16,
13、Limit: PHP webpages that do something,Semi-interesting Perl script: http:/pages.stern.nyu.edu/mjohnson/dbms/php/lookup.php Non-trivial but not huge: 60 lines, but much of its plain html Works with two-column (a,b) table Takes input from user Returns rows whose a field contains value If no/empty inpu
14、t, returns all rows Bad idea in general!,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,17,lookup.php: port of lookup.cgi,Two possible situations for running script: Page opened for the first time User entered parameter and pressed button Structure of file: Print input box and button for next search On
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C200046DATABASEMANAGEMENTSYSTEMSLECTURE22PPT

链接地址:http://www.mydoc123.com/p-379238.html