Lokang 

PHP and MySQL

Connecting

Database class sets user and database credentials for users to access the server database. It uses prepare to run SQL queries. It is also the connection to the SQL database.
 

<?php
class Database{
    public $conn;

    public function __construct(){
        $servername = "localhost";
        $username = "root";
        $password = "root";

        try {
            $this->conn = new PDO("mysql:host=$servername;dbname=yourDatabase", $username, $password);
            // set the PDO error mode to exception
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            //echo "Connected successfully";
        }
        catch(PDOException $e) {
            echo "Connection failed: " . $e->getMessage();
        }
    }
}

File: Database.php