this is my connection.php file
<?php
class Connection {
public $db_host = 'localhost';
public $db_user = 'root';
public $db_pass = '';
public $db_name = 'lybri';
public function connect() {
$this->connect_db = new mysqli($this->db_host, $this->db_user, $this->db_pass, $this->db_name);
if (mysqli_connect_errno()) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}
return true;
}
public function get_connection() {
return $this->connect_db;
}
}
$db = new Connection('localhost', 'user', 'pass', 'name');
$db->connect();
$connection = $db->get_connection();
this script is working without any errors.
and when I need to run a mysql query in another file I just include this connection.php file in to that file and doing like this.
mysqli_query($connection, "SELECT * FROM users WHERE username = '$username' AND password = '$hashedPassword' ");
I just need to know, Is this the best practice to do so.
Thank You.