...

View Full Version : Php connect to mysql database



Andy92
12-13-2006, 07:35 PM
Hi there,

This is the code to use to connect to my mysql databases...



mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());


If i put in the top of all my php snippets that get data from a database...



include('/home/sites/allsortshop.com/public_html/connect.php');


Then in connect.php i have the connection code, would it still connect?

:confused:

Tyree
12-13-2006, 08:06 PM
Yup...that's what I do...sorta. :)

JohnDubya
12-13-2006, 10:21 PM
Yep, that does it. When that external file is included, the local page uses it just like it was actually on itself. For instance, if you had variable $a on external_page.php, and you included external_page.php on internal_page.php, you could echo $a on internal_page.php, and it would print it just fine. Clear as mud? :)

Andy92
12-13-2006, 10:44 PM
Perfectly Clear.

Thank you!!! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum