Gw Temp

Menu

Tutorial - 'Connecting to Mysql' by rpgsmo

An item about General posted on

Blurb

It's kind of a follow up to 'smo's first php tutorial, this time it focuses on connecting to a mysql database.

Body

Ok, this will be very basic and imformative, it will teach you how to connect to a mysql db, step by step.

Connecting to the mySQL database is very important. You should know your mySQL database information, it should have been given to you when you got the site.  The info includes the username, password, and database name.

----BEGIN TUTORIAL----------------
1.First off, to connect to a mysql db, type:


mysql_connect();



Then, between the parenthases type quotes and the host name:



mysql_connect("localhost");



2. Okay, now you have to add the username and password.  Put them in this order: localhost, the username, then the password.  Each of them should be in quotation marks and should be seperated by commas (but the last one shouldn't have a comma after it).  It should look like this:



mysql_connect("localhost", "username", "password");



Now, type an identifier for it, name it $linkid:



$linkid = mysql_connect("localhost", "username", "password");



Ok, simple so far, is it not? Let's move on.

3.Now, choose the Database name you want to select because here we select a database. Ok, type mysql_select_db to select a database, after it type parenthases with quotes in them:



$linkid = mysql_connect("localhost", "username", "password");

mysql_select_db("name of db");



Now we want the connection to pick a Database, so after the name in quotes type a comma and the identifier of the connection:



$linkid = mysql_connect("localhost", "username", "password");

mysql_select_db("name of db", $linkid);



Very easy huh? Once you learn mysql and php it is very simple to adapt to what you learn, read jkenshin's tutorials and you will be on your way to making your own forums, it is very easy when you get the hang of mysql, and mysql can adapt to many things. Well, until next time...Have Fun!

Want more tutorials like this? Visit http://bullzeyeproduction.net for more tutorials.