We can use mysqli and PDO , to connect MySQL database in PHP. You can use any of the two, as both methods provide object oriented approach and prepared statement. The prepared sql statement is a must to prevent SQL injection and web application security. But the major difference between PDO & Mysqi is that you can connect 12 different databases using PDO, but with mysqli you can connect only MySQL database.
I think the above explanation gives you better idea which method you should select based on your project requirement.
You can use the code below to connect
$servername = “localhost”;
$username = “username”;
$password = “password”;
$conn = new PDO(“mysql:host=$servername;dbname=myDB”, $username, $password);
// set the PDO error mode to exception
echo “Connected successfully”;
echo “Connection failed: “ . $e->getMessage();
You can find free php tutorials on w3schools.com