FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

PHP Tutorial: Making a Database Connection Page

 


grim.r34p3rx
Code:
<?
$db_host = "localhost";
$db_user = "[color=red]username[/color]";
$db_password = "[color=red]password[/color]";
$db_name = "[color=red]database name[/color]";
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
?>



The bits in red, you change to your appropriate details. Sometimes your host isnt localhost, but most of the time it is.
Code:

$db_host = "localhost";
$db_user = "[color=red]username[/color]";
$db_password = "[color=red]password[/color]";
$db_name = "[color=red]database name[/color]";


Just sets the variables for the code to connect to.

Code:
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());


This just connects to the database and is ready for you to echo data!

Also, remember that when filling in your database name and user name, your cpanel user always comes in front. Example:

jack_databaseuser
jack_databasename
simplyw00x
You sir, are a SPAMMER

Don't believe me? http://tubbyanimations.com/?id=tutorials&x=view&tid=11

Get the hell out, spamface.
supjapscrapper
Wow man this section is violent! the guy just wanted to share php code! that doesn't mean he has to invent ot. All code you are ever gonna see come from the official documentation anywa so ...
be a little patient ...
Reply to topic    Frihost Forum Index -> Miscellaneous -> Tutorials

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.