php mysql database connection

Connecting to mysql via 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 Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.