php mysql database connection

Connecting to mysql via php.

<?php 
$servername = "hostname";
$username = "username";
$password = "password";
$dbname = "database";
$loggedin = false;

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) 
{
//handle it
} 
?>

this is nice to keep in a separate file (inc/conn.php) which can be included into other pages via;

require_once 'inc/conn.php';

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s