Here is the code for Make MySQL database connection with oops:
class config
{
var $servername;
var $username;
var $password;
var $database;
function database($servername, $username, $password, $database)
{
$conn=new mysqli($this->servername,$this->username,$this->password,$this->database);
if($conn->connect_error){
die("connection failed".$conn->connect_error);
}
}
}
$connect_database = new config();
$connect_database->database("localhost", "root", "", "oops");
class config
{
var $servername;
var $username;
var $password;
var $database;
function database($servername, $username, $password, $database)
{
$conn=new mysqli($this->servername,$this->username,$this->password,$this->database);
if($conn->connect_error){
die("connection failed".$conn->connect_error);
}
}
}
$connect_database = new config();
$connect_database->database("localhost", "root", "", "oops");
No comments:
Post a Comment