User Authentication using REST API and JSON Web Tokens (JWT) – Step 2

User Authentication using REST API and JSON Web Tokens (JWT) – Step 2

Create a database connection file

  • Open config folder and create a new file called database.php and place the following code.

                <?php

class Database

{

    private $host = “localhost”;

    private $db = “restapi_db”;

    private $username = “root”;

    private $password = “”;

    public $conn;

    public function getConection()

    {

        $this->conn = null;

        try {

            $this->conn = new PDO(“mysql:host=” . $this->host . “;dbname=” . $this->db, $this->username, $this->password);

            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        } catch (PDOException $e) {

            echo “connection error” . $e->getMessage();

        }

        return $this->conn;

    }

}

Post Your Comments & Reviews

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

*

*