Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Xikeon

Xikeon Avatar

***
Dedicated Member

152


August 2005
Hello.
This is my second tut here asnd in this tut I will learnt hwot o connect to a MySQL database.

There are 2 ways. One is safer but not all servers allow you to use it. So if it gives an error about the first one I am teaching you, you can just use the second one ;)

Way 1:
If you want to make a connection you need to "connect" (:P) and select the database. You do that with:
@mysql_connect();
and
@mysql_select_db();
With @mysql_connect(); you have to fill in 3 things:
1. ip or localhost
2. username for database
3. password for database
Let's go and do that.
<?php
$dbconnect = @mysql_connect("localhost", "username, "password");
?>

Now we need to use @mysql_select_db(); to select the database:
<?php
$dbcon = @mysql_connect("localhost", "username, "password");
@mysql_select_db("database name", $dbcon);
?>


And then you are connected. But what if you fill it wrong in? Then you can use "or die" to make an error
<?php
$dbcon = @mysql_connect("localhost", "username, "password") or die("Could not connect to the database!");
@mysql_select_db("database name", $dbcon) or die("Could not select the database");
?>


Well hope you understand :)

Any questions and or comments can be posted.

Thanks :)

Way 2:
As this is so easy, you can do it yourself. Follow the way1 tut and then just remove the @ infront of the functions.
so instead of
@mysql_connect
you have
mysql_connect
and instead of
@mysql_select_db
you have
mysql_select_db

:)

Thanks and hope you understand


Last Edit: Aug 25, 2005 8:10:07 GMT by Xikeon

newBookmarkLockedFalling