create database connection as a function in php code example
Example: database connection in php
<?php
$hostName = 'localhost';
$userNmame = 'root';
$password = '';
$dbname = 'topproduct';
$db_name = "mysql:host=$hostName;dbname=$dbname";
$conn = new PDO($db_name,$userNmame,$password);
if(!$conn){
echo 'Error database connection';
}