Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class c_mysql {
- private static $_instance = null;
- //connection
- private static $db_host;
- private static $db_name;
- private static $db_user;
- private static $db_pass;
- private $db_conn;
- private $db_bool_result = false;
- //sql
- private $query;
- private $resultquery;
- public $sql;
- private $where;
- private $order;
- public $numrows;
- private $resultarray = array ();
- //errors
- private $error_string;
- private $show_errors;
- function __construct() {
- $this->db_host = "****";
- $this->db_name = "****";
- $this->db_user = "****";
- $this->db_pass = "****";
- $this->error_string = "";
- $this->show_errors = true;
- $this->connect ();
- }
- public static function GetInstance() {
- if (! self::$_instance instanceof self) {
- $x = __CLASS__;
- self::$_instance = new $x ();
- }
- return self::$_instance;
- }
- public function clear_results_array() {
- $this->resultarray = array ();
- }
- public function getInsertId() {
- return @mysql_insert_id ( $this->db_conn );
- }
- public function insert($sql) {
- $query = $sql;
- $resultquery = @mysql_query ( $query );
- return ($resultquery) ? true : false;
- }
- public function delete($sql, $where) {
- $query = $sql;
- if ($where != "") {
- $query .= ' WHERE ' . $where;
- }
- $resultquery = @mysql_query ( $query );
- return ($resultquery) ? true : false;
- }
- public function update($sql, $where) {
- $query = $sql;
- if ($where != "") {
- $query .= ' WHERE ' . $where;
- }
- $resultquery = @mysql_query ( $query );
- return ($resultquery) ? true : false;
- }
- public function select($sql, $where, $groupby, $order, $limit) {
- unset ( $this->resultarray );
- $query = $sql;
- if ($where != "") {
- $query .= ' WHERE ' . $where;
- }
- if ($groupby != "") {
- $query .= ' GROUP BY ' . $groupby;
- }
- if ($order != "") {
- $query .= ' ORDER BY ' . $order;
- }
- if ($limit != "") {
- $query .= ' LIMIT ' . $limit;
- }
- $resultquery = @mysql_query ( $query );
- if ($resultquery) {
- $this->numrows = mysql_num_rows ( $resultquery );
- while ( ($this->resultarray [] = mysql_fetch_assoc ( $resultquery )) || array_pop ( $this->resultarray ) )
- ;
- }
- }
- public function mysql_errors() {
- echo mysql_errno ( $this->db_conn ) . ": " . mysql_error ( $this->db_conn ) . "<br>";
- }
- public function connect() {
- $this->db_conn = mysql_connect ( $this->db_host, $this->db_user, $this->db_pass );
- if (is_resource ( $this->db_conn )) {
- $this->db_bool_result = @mysql_select_db ( $this->db_name, $this->db_conn );
- if ($this->db_bool_result) {
- return true;
- } else {
- if ($this->show_errors) {
- $this->mysql_errors ();
- }
- return false;
- }
- } else {
- if ($this->show_errors) {
- $this->mysql_errors ();
- }
- return false;
- }
- }
- public function get_row_count() {
- return $this->numrows;
- }
- public function get_results() {
- return $this->resultarray;
- }
- public function close() {
- $this->db_bool_result = mysql_close ( $this->db_conn );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement