View Full Version : Php connect to mysql database

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...


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


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

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? :)

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

Thank you!!! :thumbsup: