Connect to a MySQL database

15 Apr

<?php

/*
Edit the database settings to your own.
To use, just include the function and
call it using <?php db_connect(); ?>

You can then do your database queries
*/

// Edit your database settings
$db_host = “localhost”;
$db_user = “username”;
$db_pass = “password”;
$db_name = “databasename”;

function db_connect() {
global $db_host;
global $db_user;
global $db_pass;
global $db_name;
$connection = mysql_connect($db_host,$db_user,$db_pass);
if (!(mysql_select_db($db_name,$connection))) {
echo “Could not connect to the database”;
}
return $connection;
}

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: