Configuring Servers and Databases with Chrome - Adding a Database (Page 4 of 5 )
Using hardcoded information in a script file may be appropriate for some limited applications, but the designer can improve the reliability of server code by allowing access to a dynamic information store without having to change any script files. Such a store can be maintained and updated to reflect the changing nature of business operations without risking any side effects caused by changes in server or client code.
Using a relational database is not a required element for this book’s sample application. If database use is inappropriate for some reason, we could write PHP “stub code” to mimic our database. The use of MySQL is included here as an example of an implementation that models true commercial applications.
The use of a relational database is the most commonly accepted technique to provide a secure and maintainable information store that server scripts can access in response to a client request. We will use the open source MySQL database engine to provide the store for our username and password information. The steps for this task are as follows:
Create the NewsSearch database.
Create a database user account to act as administrator.
Create the tables for our account name and password.
Create a database user account to act as a “guest” with read-only access to database information.
Configure PHP to use libraries to access the database.
Write the PHP scripts to communicate with the database in response to a client request.
Creating the database
Once we have installed MySQL, we create the database for our project.
Upon initial installation, MySQL has arootaccount that we can use to create a new table (refer to the glossary to set up a root password if you have not already done so). We log into the database with the following command:
mysql –u root –p
You will now be prompted for the root password. When you’re successfully logged in, you will see a welcome message that looks like this:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: Version specific information mysql>