Site Administration Page 6 - Setting Up Database Driven Websites |
In the next sections, we will go through the steps involved in creating a web enabled database. First we create the database, and populate it with some data. After that is done, we create some PHP scripts that talk to the database and see it all work. Building the DatabaseMake sure the MySQL server processes are running. If they aren't start them manually by running:
Now we start the MySQL client as the administrator, this time we will see a password prompt: Creating the database Create a database called example with the command create database example;. When using the MySQL client, remember to put a semicolon (;) after each command: Create a new table Create a table in the example database called mytable:
Here's a handy tip that will save you some typing. Use the up arrow and down arrow keys to recall back the previous/next lines you typed in. Adding some dataNow let's populate this with some data, we will insert a few entries into the table. Enter in the following INSERT statments:
Make sure everything is there by issuing with a SELECT statement:
Looking good so far? Excellent. Creating a Database UserWe've created the database and put some data in there, now we must create a user account. This user will have access to this database. We create the user and grant privileges with the GRANT command:
This creates a new user called webuser. This user can connect only from localhost, and he has the ability to connect to the example database. Next we have to specify what operations webuser can perform:
This gives webuser the ability to execute SELECT, INSERT, and DELETE queries on every table of the example database. Our work is done here, exit the MySQL client:
blog comments powered by Disqus |