How to connect PHP to MySQL using WAMP

Written by stephen byron cooper Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to connect PHP to MySQL using WAMP
WAMP includes a MySQL server. (WAMP)

WAMP stands for Windows, Apache, MySQL and PHP. It is a free bundle of applications that enables a Web server to run on a Windows PC. PHP is a programming language in which many Web pages are written. Apache is a Web server, which means it handles access to Web pages by process incoming requests. MySQL is a relational database system. Installing WAMP gives anyone the ability to test newly developed Web pages locally before uploading them to a remote server.

Skill level:
Moderately Challenging

Other People Are Reading

Things you need

  • WAMP
  • Web page developer tool

Show MoreHide

Instructions

    Create a database

  1. 1

    Double click on the WAMP Server icon that was installed on your desktop during installation. This will start the server running. You will see a red W in your services tray at the bottom of your screen turn from red to green.

  2. 2

    Click on the green W in the services tray. Select phpMyAdmin from the pop-up menu. In the application click the “Databases” tab at the top of the screen. For this example, we'll use a database of dogs; your categories will reflect the database you want to create. Type the name “dogs” in the “Create new database” field and the click the “Create” button.

  3. 3

    In the next screen, enter “breeds” in the “Create new table” “Name field and enter “3” (without the quotes in both cases). Press the Go button. A new screen appears enabling you to enter details of each field in the table.

  4. 4

    Enter “dog_id” in the “Field” box in the first row. Give it a “Type” of “INT” and a “Length” of “20.” Select “PRIMARY” from the ”Index” pick list and check the “A_I” box. Name the “Field” in the next row “dog_name,” give it a “Type” of “VARCHAR” and a “Length” of “100.” Call the third field “breed” and make that “VARCHAR” with a length of “100.” Click the “Save” button at the bottom of the screen.

  5. 5

    Press the “Insert” tab at the top of the screen and fill in a record. Leave the dog_id field blank. Enter “Fluffy” for dog name and “Maltese” for breed. Press the “Go” button to save the record.

    Create PHP file

  1. 1

    Locate the folder called c:\wamp\www on your C drive. This folder was created during the installation of WAMP. Create a folder beneath this to hold all the files of your current Web development project. Move two files from the www folder to your new folder. These files are called index.php and testmysql.php.

  2. 2

    Open your Web development tool. Create a new site in the developer and specify you want to work with PHP and MySQL. You should also specify that you will be editing and testing locally. Set the default directory for the site to the directory you created under c:\wamp\www.

  3. 3

    Create a Database connection in your developer and specify a MySQL connection. Call it con_dogs, set the MySQL server to localhost and write “root” in the “Username” field. Leave password blank and select the database name from a list of databases in your local MySQL system. Select “dogs“ as the database.

  4. 4

    Create a form with two fields, “Dog Name” and “Breed.” Add a “Submit” button and a “Cancel” button.

  5. 5

    Add Server Behaviors to the form. Specify the con_dogs connection to enable the developer tool to connect to the database and fetch table details. Link the “Dog Name” field to the “dog_name” column in the table. Link the “Breed” form field to the “breed” column in the table.

  6. 6

    Save the program and run it from the developer tool. Use the form to insert a record into the table. Go back to the WAMP server to see the new record in the table.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.