Administration
  Home arrow Administration arrow Page 6 - Setting Up Database Driven Websites
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ADMINISTRATION

Setting Up Database Driven Websites
By: Ying Zhang
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 15
    1999-05-20


    Table of Contents:
  • Setting Up Database Driven Websites
  • Requirements
  • Installing MySQL
  • Installing Apache
  • Installing PHP
  • Creating the Database
  • Making a PHP Script
  • Testing the Script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Setting Up Database Driven Websites - Creating the Database
    ( Page 6 of 8 )

    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 Database

    Make sure the MySQL server processes are running. If they aren't start them manually by running:


    # /usr/local/mysql/support-files/mysql.server start

    Now we start the MySQL client as the administrator, this time we will see a password prompt:


    # mysql -u root -p Enter password: newpassword Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 to server version: 3.22.21 Type 'help' for help. mysql>
    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:


    mysql> create database example; Query OK, 1 row affected (0.03 sec) mysql> use example; Database changed
    Create a new table

    Create a table in the example database called mytable:


    mysql> CREATE TABLE mytable ( -> name CHAR(30), -> phone CHAR(10) -> ); Query OK, 0 rows affected (0.00 sec)

    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 data

    Now let's populate this with some data, we will insert a few entries into the table. Enter in the following INSERT statments:


    mysql> INSERT INTO mytable VALUES ("Homer Simpson", "555-1234"); Query OK, 1 row affected (0.05 sec) mysql> INSERT INTO mytable VALUES ("Bart Simpson", "555-4321"); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO mytable VALUES ("Lisa Simpson", "555-3214"); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO mytable VALUES ("Marge Simpson", "555-2314"); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO mytable VALUES ("Maggie Simpson", "555-3142"); Query OK, 1 row affected (0.00 sec)

    Make sure everything is there by issuing with a SELECT statement:


    mysql> SELECT * FROM mytable; +----------------+----------+ | name | phone | +----------------+----------+ | Homer Simpson | 555-1234 | | Bart Simpson | 555-4321 | | Lisa Simpson | 555-3214 | | Marge Simpson | 555-2314 | | Maggie Simpson | 555-3142 | +----------------+----------+ 5 rows in set (0.00 sec)

    Looking good so far? Excellent.

    Creating a Database User

    We'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:


    mysql> GRANT usage -> ON example.* -> TO webuser@localhost; Query OK, 0 rows affected (0.15 sec)

    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:


    mysql> GRANT select, insert, delete -> ON example.* -> TO webuser@localhost; Query OK, 0 rows affected (0.00 sec)

    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:


    mysql> exit Bye


     
     
    >>> More Administration Articles          >>> More By Ying Zhang
     

       

    ADMINISTRATION ARTICLES

    - Network Booting via PXE: the Basics
    - Scalix: Linux Administrator`s Guide
    - Network Administration with FreeBSD 7
    - Components of an Information Architecture
    - The Anatomy of an Information Architecture
    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT