tailieunhanh - Beginning Perl Third Edition PHẦN 10
Nếu lớp học cung cấp phương pháp này, nó phải chịu trách nhiệm cho bất cứ nhiệm vụ nào cần phải được thực hiện trước khi đối tượng bị xử lý. Ví dụ, đối tượng phiên FTP của bạn sẽ muốn đảm bảo rằng nó đã đóng cửa các kết nối đến máy chủ từ xa. | CHAPTER 15 PERL AND DBI my phone phone sth- fetchrow print number and end HTML print Call musician at phone. end_html After calling Geddy Lee our music fan might want to see the instruments Thom Yorke plays so our curious person goes back to the initial page select Thom from the drop-down menu and clicks Show instruments. That produces this page Instruments played by Thom Yorke - Mozilla Firefox File Edit View History Bookmarks Tools Help @ http localhost cgi-bin ỊCỊv I Google Most visited Getting started Latest Headlines Instruments played by Thom Yorke Thom Yorke plays keyboards guitar vocals Done And here s the code that builds the page elsif param Show instruments the user wants to see the instruments the musician plays start the HTML print header start_html Instruments played by musician h1 Instruments played by musician musician plays ul 384 CHAPTER 15 PERL AND DBI We see that the user wants to show the musician s instruments so we start the HTML print some text and then start an unordered list a bullet list . Then we go to the code that queries the database query the database with a table join and retrieve the instruments played by musician my dbh DBI- connect DBI mysql musicians_db musicfan CrimsonKing my sth dbh- prepare SELECT instrument FROM instruments JOIN what_they_play ON JOIN musicians ON WHERE or die prepare failed . dbh- errstr sth- execute musician or die execute failed . sth- errstr Using the table join we ve seen a few times in this chapter we find all the instruments that the musician plays bringing us to the code that prints the instruments my instrument print all the instruments in a bullet list while instrument sth- fetchrow print li instrument li Notice that each instrument is printed within an li tag which makes it into a bullet item in the list. Finally we get to the end of the unordered list and the end of the HTML finish
đang nạp các trang xem trước