Thiết kế mạng xã hội với PHP - 6

Kết nối với cơ sở dữ liệu và quản lý kết nối Để kết nối tới cơ sở dữ liệu nhiều, chúng ta cần phải duy trì một hồ sơ về các kết nối khác nhau. Điều này có thể được thực hiện bằng cách lưu trữ mỗi tài nguyên kết nối trong một mảng, giữ một kỷ lục khi mà các mục trong mảng này là kết nối hoạt động. Khi một truy vấn được thực thi, nó sẽ thực hiện các truy vấn với các kết nối đang hoạt động | Planning and Developing the Core Framework Connecting to the database and managing connections In order to connect to multiple databases we need to maintain a record of the different connections. This can be done by storing each connection resource in an array keeping a record as to which of the items in this array is the active connection. When a query is executed it will perform the query against the currently active connection. php Database management access class basic abstraction author Michael Peacock version class Mysqldb Allows multiple database connections each connection is stored as an element in the array and the active connection is maintained in a variable see below private connections array Tells the DB object which connection to use setActiveConnection id allows us to change this private activeConnection 0 Queries which have been executed and the results cached for later primarily for use within the template engine private queryCache array Data which has been prepared and then cached for later usage primarily within the template engine private dataCache array Number of queries made during execution process private queryCounter 0 ----------------------------------- 32 ------------------------------- Download from Wow eBook Chapter 2 Record of the last query private last Reference to the registry object private registry Construct our database object public function construct Registry registry this- registry registry To connect to the database we pass the database server host username and password and of course the name of the database we wish to connect to. The resulting connection is stored in our connections array and the connection ID Array key is returned. Create a new database connection @param String database hostname @param String database username @param String database password @param String database we are using return int the id of the new connection public function newConnection host user password database this- .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
106    104    3    28-04-2024
Đã 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.