<?php
/**
* function to connect to mysql database with comments
* @param string $host Hostname of the database
* @param string $user Username of the database
* @param string $pass Password of the database
* @param string $dbname Name of the database
* @return $conn
*/
function connectToDB($host, $user, $pass, $dbname) {
// create connection
$conn = new mysqli($host, $user, $pass, $dbname);
// check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// return connection
return $conn;
}
//example
$conn = connectToDB("localhost", "root", "", "comments");
//output
$conn; //object(mysqli)#1 (0) { }
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)