TAILIEUCHUNG - PHP 5 Recipes A Problem-Solution Approach 2005 phần 10

Trong PHP 5, cơ sở hạ tầng của mô hình hướng đối tượng đã được viết lại để làm việc được với các biến điều khiển đối tượng (object handle). Nếu bạn không nhân bản một đối tượng một cách tường minh bằng cách dùng từ khóa clone thì bạn sẽ không bao giờ sao chép các đối tượng của mình được. | 556 15-3 RETRIEVING AND DISPLAYING RESULTS The next thing you must do is select a database. try if mysql_select_db whichdb db throw new exception Sorry database could not be opened. catch exception e echo e- getmessage A function to close the connection to MySQL. function closedatabase db When you finish up you have to close the connection. mysql_close db First open a connection to the database. db opendatabase localhost apress testing Then select a database. selectdb cds db Now let s create a script to output the information found within the table. if aquery mysql_query SELECT FROM cd ORDER BY cdid ASC You can loop through the rows in the table outputting as you go. while adata mysql_fetch_array aquery echo ID . adata cdid . br echo Title . stripslashes adata title . br echo Artist . stripslashes adata artist . br echo -------------------------------- br else echo mysql_error Then close the database. closedatabase db ID 1 Title Chuck Artist Sum 41 ID 2 Title Meteora Artist Linkin Park 15-4 MODIFYING DATA 557 ID 3 Title Mezmerize Artist System of a Down ID 4 Title Greyest of Blue Skies Artist Finger Eleven How It Works The major difference between this code sample and the previous one is that you have placed the selection of a database into a function for portability. Past that you simply check if the query is valid and if not echo the error and then loop through all the resulting rows that are returned from the mysql_fetch_array function. As you loop through the different rows you can output the value of the row in the array by referencing the name of the field in the database. By doing this as you can see from the results you can succeed in outputting the entire contents of the cd table. 15-4. Modifying Data Obviously database functionality would be pretty useless if the data stored in the database itself could only remain static. Luckily MySQL provides you with a means to modify certain data. The general method for modifying a set of data is to reference a .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.