欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > PPT文档下载
    分享到微信 分享到微博 分享到QQ空间

    C20.0046- Database Management SystemsLecture #22.ppt

    • 资源ID:379238       资源大小:107KB        全文页数:31页
    • 资源格式: PPT        下载积分:2000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要2000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C20.0046- Database Management SystemsLecture #22.ppt

    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

    15、button click, parameter is sent to this pages url (Try to) read input parameter Open MySQL connection Run query Print results in a table Disconnect from MySQL,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,18,Insert/delete Perl/PHP example,Similar to search exampleNB: form has two buttonshttp:/pages.ste

    16、rn.nyu.edu/mjohnson/dbms/perl/update.cgi http:/pages.stern.nyu.edu/mjohnson/dbms/perl/updatecgi.txthttp:/pages.stern.nyu.edu/mjohnson/dbms/php/update.php http:/pages.stern.nyu.edu/mjohnson/dbms/php/updatephp.txt,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,19,Master-detail Perl/PHP example,Idea: displ

    17、ay list of regions; When region clicked on, display its countriesMechanism: pass GET param in link, not with a FORMhttp:/pages.stern.nyu.edu/mjohnson/dbms/php/cia.php?id= http:/pages.stern.nyu.edu/mjohnson/dbms/php/ciaphp.txthttp:/pages.stern.nyu.edu/mjohnson/dbms/perl/cia.cgi http:/pages.stern.nyu.

    18、edu/mjohnson/dbms/perl/cia.pl,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,20,Tutorials on PHP,Some material drawn from the following good tutorials: http:/PHP introduction and examples: http:/www.scit.wlv.ac.uk/jphb/sst/php/ Interactive PHP with database access: http:/www.scit.wlv.ac.uk/jphb/sst/php/

    19、gazdb.html Longer PHP/MySQL Tutorial from webmonkey: http:/ insert/update/delete example from webmonkey: http:/ MySQL/Perl/PHP page from U-Wash: http:/www.washington.edu/computing/web/publishing/mysql-script.html,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,21,Pros & cons,PHP v. Perl v. Java servlets

    20、v. : http:/ is fast Perl has JDBC-like DBI/DBD interface PHP is fast Perl is good for much more than web dev,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,22,Advice for use of novel languages,Rerun often Dont write the whole thing and then try to runUse frequent prints to be sure of var vals (While deb

    21、ugging)When stuck, picture continuum from your current program to some other program other prog. works but doesnt do what you want change either/both, step by step, until they meet in the middleGoogle is your friend Search for error messages, situations,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,23,

    22、Thats really all, folks!,Q: Is this enough to get a job coding PHP? A: Again, probably not. But: most jobs are just programming-in-PHP or administering-Oracle Being able to acquire new skills when needed is a good thingBut: again pretty easy to produce a semi-interested site with a few copies of loo

    23、kup.php and cia.php.Dont like PHP either? Lots of other choices, but again, youre strongly discouraged from using something else for your project unless you know what youre doing.,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,24,New-old topic: Transactions,So far, have simply issued commands Ignored xa

    24、ctsRecall, though: an xact is an operation/set of ops executed atomically In one instant ACID test: Xacts are atomic Each xact (not each statement) must leave the DB consistent,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,25,Default xact behavior,An xact begins upon login By default, xact lasts until

    25、logoff Except for DDL statements They automatically commitExamples with two views of emp,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,26,Direct xact instructions,At any point, may explicitly COMMIT: SQL COMMIT; Saves all statements entered up to now Begins new xactConversely, can ROLLBACK SQL ROLLBACK

    26、; Cancels all statements entered since start of xactExample: delete from emp; or delete junk;,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,27,Direct xact instructions,Remember, DDL statements are auto-committed They cannot be rollbackedExamples:Q: Why doesnt rollback “work”?,drop table junk; rollback;

    27、,truncate table junk; rollback;,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,28,Savepoints,Xacts are atomic Can rollback to beginning of current xactBut might want to rollback only part wayMake 10 changes, make one bad change Want to: roll back to before last changeDont have Word-like multiple undo Bu

    28、t do have savepoints,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,29,Savepoints,Create a savepoint:emp example:,-changes SAVEPOINT sp1; -changes SAVEPOINT sp2; -changes SAVEPOINT sp3 -changes ROLLBACK TO sp2; ROLLBACK TO sp1;,SAVEPOINT savept_name;,Can skip savepoints But can ROLLBACK only backwards C

    29、an ROLLBACK only to last COMMIT,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,30,AUTOCOMMIT,Finally, can turn AUTOCOMMIT on: SQL SET AUTOCOMMIT ON; Can put this in your config file Can specify through JDBC, etc.Then each statement is auto-committed as its own xact Not just DDL statements,M.P. Johnson, DBMS, Stern/NYU, Spring 2005,31,For next time,Read chapter 21 Lots of interesting security topicsStart proj5!,


    注意事项

    本文(C20.0046- Database Management SystemsLecture #22.ppt)为本站会员(孙刚)主动上传,麦多课文档分享仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文档分享(点击联系客服),我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1 

    收起
    展开