PHP Connection to MySQL

Posted on

To access a MySQL database in PHP you can use the following script:

<?php
$dbhost = 'mysql.myserver.net';
$dbuser = 'myname';
$dbpass = 'mypassword';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
('Error connecting to mysql');

$dbname = 'mydatabase';
mysql_select_db($dbname);
?>

Remember to change the Host address to the address of your MySQL database; also you will need to change the dbname, dbuser and dbpass parameters as appropriate.

This entry was posted in Web Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *