Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mysql extends DAL {
- //Class Variables
- public $Host;
- public $User;
- public $pass;
- public $dbname;
- function __construct($Host, $User, $Pass, $dbname, $query = NULL, $mode = NULL, $errorlocation = NULL) {
- $this->Host = $Host;
- $this->User = $User;
- $this->pass = $Pass;
- $this->dbname = $dbname;
- $this->connect();
- if($mode == 'row' && $query) {
- $this->result = $this->fetch_row($query);
- }
- elseif($mode == 'rows' && $query) {
- $this->result = $this->fetch_rows($query);
- }
- elseif($mode == NULL && $query) {
- $this->query($query);
- }
- }
- public function connect() {
- $this->set_last_error(null);
- $this->db = new mysqli('p:' . $this->Host,$this->User, $this->pass, $this->dbname);
- if (!$this->db) {
- $this->set_last_error('Could not connect to database');
- }
- }
- public function fetch_rows($query) {
- //process params
- $query = $this->process_params($query);
- $this->set_last_error(null);
- $result = $this->db->query($query);
- $all = array();
- if($result) {
- while ($row = $result->fetch_assoc()) {
- $all[] = $row;
- }
- }
- return $all;
- }
- public function query($query) {
- $this->set_last_error(null);
- //process params
- $query = $this->process_params($query);
- $result = $this->db->query($query);
- }
- public function fetch_row($query) {
- //process params
- $query = $this->process_params($query);
- $this->set_last_error(null);
- if($result = $this->db->query($query)) {
- }
- else {
- $this->set_last_error('Could not run query: ' . $this->db->error);
- }
- return $result->fetch_row();
- }
- public function get_column_names($table) {
- $query = "SELECT * FROM `" . $table . "`";
- $result = $this->db->query($query);
- $row = $result->fetch_assoc();
- $columns = array_keys($row);
- return $columns;
- }
- function get_primary_key($table) {
- $result = $this->db->query("SHOW KEYS FROM `$table` WHERE Key_name = 'PRIMARY'");
- echo $table;
- var_dump($result);
- $row = $result->fetch_row();
- return $row[4];
- }
- }
Add Comment
Please, Sign In to add comment