Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DBConnection extends Mysqli
- {
- protected $db;
- public function __construct()
- {
- global $config;
- $this->db = parent::__construct($config['dbhost'], $config['dbuser'], $config['dbpass'], $config['dbname']);
- if( $this->db->connect_errno )
- {
- die("Error database connection. ".$this->db->connect_error);
- exit;
- }
- }
- public function insert($table, $data)
- {
- if( is_array($data) )
- {
- $insert_data = "";
- foreach($data as $column => $value)
- {
- $insert_data .= $column."='".$this->db->real_escape_string($value)."' ";
- }
- $insert_data = trim($insert_data);
- if( $insert_data !== "" )
- {
- $qry = "INSERT INTO $table SET $insert_data";
- $a = $this->db->query($qry) or die("Insert query error. ".$this->db->error);
- return $a;
- }
- }
- else
- {
- return "Insert query error. Inserted data must be in array";
- exit;
- }
- }
- public function __destruct()
- {
- $this->db->close();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement