PHP and MySQL Web Development - P54

PHP and MySQL Web Development - P54: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Using a Generic Database Interface PEAR DB 237 is a standard for connections to databases. It has the most limited functionality of any of the function sets for fairly obvious reasons. If you have to be compatible with everything you can t exploit the special features of anything. In addition to the libraries that come with PHP database abstraction classes such as Metabase or PEAR DB are available that allow you to use the same function names for each different type of database. Using a Generic Database Interface PEAR DB We will look at a brief example using the PEAR DB abstraction layer. This is one of the core components of PEAR and probably the most widely used of all the PEAR components. If you have PEAR installed then you should already have DB. If not please refer to the PEAR Installation section in Appendix A. For comparative purposes let s look at how we would have written our search results script differently using DB. Listing Retrieves Search Results from our MySQL Database and Formats Them for Display html head title Book-O-Rama Search Results title head body h1 Book-O-Rama Search Results h1 php create short variable names searchtype HTTP_POST_VARS searchtype searchterm HTTP_POST_VARS searchterm searchterm trim searchterm if searchtype searchterm echo You have not entered search details. Please go back and try again. exit searchtype addslashes searchtype searchterm addslashes searchterm set up for using PEAR DB require user bookorama pass bookorama123 host localhost 238 Chapter 10 Accessing Your MySQL Database from the Web with PHP Listing Continued db_name books set up universal connection string or DSN dsn mysql user pass@ host db_name connect to database db DB connect dsn true check if connection worked if DB isError db echo db- getMessage exit perform query query select from books where . searchtype. like . searchterm. result db- query query check that result was ok if DB isError result echo db- getMessage exit .

Không thể tạo bản xem trước, hãy bấm tải xuống
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.