Created
April 14, 2019 23:39
-
-
Save mhmohon/a87fc0faa8755cd6e089a8313b984cfc to your computer and use it in GitHub Desktop.
Database Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MySqlDrive | |
{ | |
private $host = 'localhost'; | |
private $user = 'root'; | |
private $password = ''; | |
private $db = 'codeigniter_crud'; | |
private $db_handle; | |
public function __construct() | |
{ | |
$this->db_handle = mysqli_connect($this->host, $this->user, $this->password, $this->db); | |
if(!$this->db_handle) die("Unable to connect to mysql: " . mysqli_error($this->db_handle)); | |
if(!mysqli_select_db($this->db_handle, $this->db)) die ("Unable to connect to database: " . mysqli_error($this->db_handle)); | |
} | |
public function db_connect() | |
{ | |
return $this->db_handle; | |
} | |
public function excute_query($query) | |
{ | |
$result = mysqli_query($this->db_handle, $query); | |
return !$result ? FALSE : TRUE; | |
} | |
public function insert($query) | |
{ | |
return $this->excute_query($query); | |
} | |
public function read($query) | |
{ | |
$result = mysqli_query($this->db_handle, $query); | |
$row = mysqli_num_rows($result); | |
$data = array(); | |
if($row){ | |
while ($row = mysqli_fetch_assoc($result)) | |
{ | |
$data = $row; | |
} | |
} | |
return $data; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment