Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Serenity
- * Date: 30-sep-2010
- * Time: 15:08:44
- * To change this template use File | Settings | File Templates.
- */
- include('result.php');
- class Mysql {
- private $connection;
- private $database;
- private static $executed_querys;
- public function __construct($host = '', $user = '', $pass = '', $database = '') {
- if (!empty($host) && !empty($user)) {
- $this -> connect($host, $user, $pass);
- }
- if (!empty($database)) {
- $this->select_database($database);
- }
- mysql_query("SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY'", $this->connection);
- }
- public function connect($host, $user, $pass = '') {
- $this->connection = mysql_connect($host, $user, $pass);
- if (!$this->connection) {
- throw new Exception('could not connect to MYSQL Server');
- }
- }
- public function select_database($database_name) {
- if (!empty($database_name)) {
- if (empty($this->database)) {
- $this->database = $database_name;
- }
- if (!mysql_select_db($database_name, $this->connection)) {
- throw new Exception('Could not select database');
- }
- }
- }
- public function execute($query) {
- if (!mysql_query($query, $this->connection)) {
- throw new Exception('could not execute the query', $query);
- }
- self::$executed_querys++;
- return mysql_affected_rows($this->connection);
- }
- public function query($query) {
- if (!$result = mysql_query($query, $this->connection)) {
- throw new Exception("could not execute the query \n $query");
- }
- self::$executed_querys++;
- return new result($result);
- }
- public function getTotalQuerys() {
- return self::$executed_querys;
- }
- public function __destruct() {
- mysql_close($this->connection);
- }
- public function getConnection() {
- return $this->connection;
- }
- public function getDatabase() {
- return $this->database;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement