tailieunhanh - Tạo mạng xã hội với PHP - part 6

Tham khảo tài liệu 'tạo mạng xã hội với php - part 6', công nghệ thông tin, đồ họa - thiết kế - flash phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 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 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- connections .