October 17, 2018 -
Database Class,MYSQLI CRUD Series,OOP CRUD,PHP,Programming Notes
No comments
Database Class: MYSQLI CRUD OOP Series
Step 1. Create Database Class
This class will establish the database connection
in every functions of the system that will be created. Filename: class.db.php
Code:
<?php
class DBconn{
public $dbconn;
public function __construct(){
$server = 'localhost';
$user ='root';
$pass = '';
$dbname = 'exam';
$this->dbconn = mysqli_connect($server,$user,$pass,$dbname);
if (mysqli_connect_errno()){
echo 'Error: Could not connect to database.';
exit;
}else{
//echo 'Connected';
}
}
}
$test = new dbconn();
?>
Discussion:
By default all function in class are automatically assigned as public.
$dbconn variable will be used as the database connection across classes.
0 comments:
Post a Comment
If possible, leave a positive comment. No hate speech or elicit comments. Thank you.