ImageVerifierCode 换一换
格式:PPT , 页数:31 ,大小:107KB ,
资源ID:379238      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-379238.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

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

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

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