Created
August 12, 2017 11:20
-
-
Save tanzilhuda/f3b11348343376ae41f710793593cc1b to your computer and use it in GitHub Desktop.
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
config.php | |
------------ | |
<?php | |
define("DB_HOST", "localhost"); | |
define("DB_USER", "root"); | |
define("DB_PASS", ""); | |
define("DB_NAME", "your_db_name"); | |
?> | |
====================================== | |
Database Class: | |
---------------- | |
<?php | |
Class Database{ | |
public $host = DB_HOST; | |
public $user = DB_USER; | |
public $pass = DB_PASS; | |
public $dbname = DB_NAME; | |
public $link; | |
public $error; | |
public function __construct(){ | |
$this->connectDB(); | |
} | |
private function connectDB(){ | |
$this->link = new mysqli($this->host, $this->user, $this->pass, | |
$this->dbname); | |
if(!$this->link){ | |
$this->error ="Connection fail".$this->link->connect_error; | |
return false; | |
} | |
} | |
// Select or Read data | |
public function select($query){ | |
$result = $this->link->query($query) or | |
die($this->link->error.__LINE__); | |
if($result->num_rows > 0){ | |
return $result; | |
} else { | |
return false; | |
} | |
} | |
// Insert data | |
public function insert($query){ | |
$insert_row = $this->link->query($query) or | |
die($this->link->error.__LINE__); | |
if($insert_row){ | |
return $insert_row; | |
} else { | |
return false; | |
} | |
} | |
// Update data | |
public function update($query){ | |
$update_row = $this->link->query($query) or | |
die($this->link->error.__LINE__); | |
if($update_row){ | |
return $update_row; | |
} else { | |
return false; | |
} | |
} | |
// Delete data | |
public function delete($query){ | |
$delete_row = $this->link->query($query) or | |
die($this->link->error.__LINE__); | |
if($delete_row){ | |
return $delete_row; | |
} else { | |
return false; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Insert data
public function insert($query){
$insert_row = $this->link->query($query) or
die($this->link->error.LINE);
if($insert_row){
return $insert_row;
} else {
return false;
}
}
===============
$insert_row = $this->link->query($query) or
die($this->link->error.LINE);
==> chào anh ơ dòng nay bao lỗi cú pháp , trương hơp nay mình phải xư lý thế nào ã cảm ơn anh==
==> Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax;