Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mysql
- {
- var $connection;
- var $data;
- function mysql($host, $user, $pwd, $database, $charset)
- {
- $this->connection = NULL;
- $this->data = NULL;
- $this->connection = mysqli_connect($host, $user, $pwd) or $this->error("mysql_connect error");
- mysqli_select_db($this->connection, $database) or $this->error("mysql_select_db error");
- mysqli_set_charset($this->connection, $charset);
- }
- function restart($host, $user, $pwd, $database)
- {
- if ($this->data != NULL && $this->data != 1)
- mysqli_free_result($this->data);
- if ($this->connection != NULL)
- mysqli_close($this->connection);
- $this->connection = mysqli_connect($host, $user, $pwd) or $this->error("mysql_connect error");
- mysqli_select_db($this->connection, $database) or $this->error("mysql_select_db error");
- }
- function fetch_row()
- {
- return mysqli_fetch_row($this->data);
- }
- function fetch_array()
- {
- return mysqli_fetch_array($this->data);
- }
- function result($row_num, $value_name)
- {
- return mysqli_result($this->data, $row_num, $value_name);
- }
- function disconnect()
- {
- if ($this->connection != NULL)
- {
- mysqli_close($this->connection);
- $this->connection = NULL;
- }
- }
- function num_rows()
- {
- return (mysqli_num_rows($this->data));
- }
- function destroy()
- {
- if ($this->data != NULL && $this->data != 1)
- mysqli_free_result($this->data);
- $this->disconnect();
- }
- function query($query_string)
- {
- if ($this->data != NULL)
- {
- if ($this->data != 1)
- mysqli_free_result($this->data);
- $this->data = NULL;
- }
- $this->data = mysqli_query($this->connection, $query_string) or $this->error("mysql_query error");
- if ($this->data)
- return TRUE;
- else
- return FALSE;
- }
- function query_nodie($query_string)
- {
- if ($this->data != NULL && $this->data != 1)
- {
- if ($this->data != 1)
- mysqli_free_result($this->data);
- $this->data = NULL;
- }
- $this->data = mysqli_query($query_string, $this->connection);
- if ($this->data)
- return TRUE;
- else
- return FALSE;
- }
- function error($header)
- {
- die($header.": ".mysqli_error($this->connection));
- }
- function lock($rule)
- {
- $this->query("LOCK TABLES $rule") or $this->error("mysql LOCK TABLES error");
- }
- function unlock()
- {
- $this->query("UNLOCK TABLES") or $this->error("mysql UNLOCK TABLES error");
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement