Support > Knowledgebase > Databases > How can I connect to my MySQL Database from a php script?
 » How can I connect to my MySQL Database from a php script?

You can connect to your database from within a php script by using the following code:

<?
mysql_connect('localhost','yourdatabaseusername','yourdatabasepassword') or die (mysql_error());
mysql_select_db("yourdatabasename") or die(mysql_error());
?>

You must enter the database name, username and password of a database you have created in order to connect to it. For more information about how to create a database please see the related article: How do I create a Database?

Was this answer helpful?   Add to Favourites   Print this Article