Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tạo một tập tin để Store Giây chứng nhận cơ sở dữ liệu Để giữ cho các thông tin cơ sở dữ liệu tách biệt với phần còn lại của ứng dụng để dễ dàng, bạn muốn sử dụng một file cấu hình. Tạo một tập tin mới gọi là db-cred.inc.php trong thư mục cấu hình | CHAPTER 4 BUILD AN EVENTS CALENDAR Note That the Calendar class constructor accepts an optional dbo argument that is passed in turn to the DB_Connect constructor. This allows you to create a database object and pass it for use in the class easily. Creating a File to Store Database Credentials To keep the database credentials separate from the rest of the application for easy maintenance you want to use a configuration file. Create a new file called db-cred.inc.php in the config folder sys config db-cred.inc.php . Inside create an array called C for constants and store each piece of data as a new key-value pair php Create an empty array to store constants C array The database host URL C DB_HOST localhost The database username C DB_USER root The database password C DB_PASS The name of the database to work with C DB_NAME php-jquery_example 131 CHAPTER 4 BUILD AN EVENTS CALENDAR Note Initializing C as an empty array is a safeguard against any tainted pieces of data being stored in C and defined as constants. This is a good habit especially when dealing with sensitive data. Save this file. If you re not using XAMPP or if you ve modified the default database credentials you ll need to substitute your own host username password and database name in the code. Creating an Initialization File At this point your database credentials still aren t stored as constants. You ll be using an initialization file to handle this. An initialization file collects data loads files and organizes information for an application. In this example it will load and define all necessary constants create a database object and set up an automatic loading function for classes. Other functionality will be added later on as it becomes necessary. Create a file called init.inc.php and place it in the core folder sys core init.inc.php . Inside add the following php Include the necessary configuration info include_once . sys config db-cred.inc.php Define constants for configuration info foreach C as name