Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Mysql_DB
- {
- private
- $host = 'localhost',
- $port = ,
- $dbname = '',
- $user = '',
- $password = '';
- protected
- $handler,
- $base;
- private static
- $instance = null;
- private function __construct()
- {
- $this->handler = mysql_connect($this->host.':'.$this->port, $this->user, $this->password) or die('Could not connect: ' . mysql_error());
- mysql_query("SET NAMES utf8");
- $this->base = mysql_select_db($this->dbname, $this->handler) or die('Could not select db: ' . mysql_error());
- }
- public function query($query)
- {
- return mysql_query($query, $this->handler);
- }
- public function hasResult($query)
- {
- $result = mysql_num_rows( $this->query($query) );
- return ($result > 0 ) ? true : false;
- }
- public function getArray($query)
- {
- $array = array();
- $result = $this->query($query);
- while ( $row = mysql_fetch_assoc( $result ) )
- {
- $array[] = $row;
- }
- return $array;
- }
- public function getOne($query)
- {
- return mysql_fetch_assoc ( $this->query($query) );
- }
- public static function getInstance()
- {
- if( self::$instance == null )
- {
- self::$instance = new Mysql_DB();
- }
- return self::$instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement