PHP Tutorial - MySQL Connect
Digg! This Page
Introduction
This tutorial will teach you, very simply how to connect to your database and show an error if it doesn't connect correctly.Step 1
First of all we need to open our PHP tags.Step 2
Now we'll need to start by using a function called mysql_connect(). It hold 3 properties (1st - Database Hostname (eg; localhost in this tutorial), 2nd - Database Username (eg; foo in this tutorial), 3rd - Database Password (eg; bar in this tutorials)).Now just incase we have an error with those details we entered you can add a "or die" option at the end of it.
This will then show an error message and stop the rest of the mysql stuff from loading if it cannot connect.
Step 3
Ok, so now we have connected to the database, we need to connect to the table in the database using the function mysql_select_db, which has one property (1st - table name (eg; dalehay in this tutorial)) - To find out what the table name is, just log into your phpMyAdmin and check the name at the top of the fields in the left menu (it usually has a number in brackets next to it).Now obviously if there IS a problem with that line, we also want it to stop and show an error message, so just like before add a "or die" tag at the end like so:
Nice and simple. :-)
















