Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Serenity
- * Date: 6-okt-2010
- * Time: 19:15:32
- * To change this template use File | Settings | File Templates.
- */
- class Mysql {
- private $connection;
- private $database;
- private static $executed_querys;
- public function __construct($host = '', $user = '', $pass = '', $database = '') {
- echo $pass;
- if (!empty($host) && !empty($user)) {
- $this -> connect($host, $user, $pass);
- }
- if (!empty($database)) {
- $this->select_database($database);
- }
- if (!empty($host) && !empty($user) && !empty($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 :\n<br>\n<br>$query \n<br>\n<br>");
- }
- 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<br>\n<br> $query\n<br>\n<br>");
- }
- self::$executed_querys++;
- return new mysql_result($result);
- }
- public function getTotalQuerys() {
- return self::$executed_querys;
- }
- public function __destruct() {
- // mysql_close($this->connection);
- }
- public function disconnect(){
- // $this->__destruct();
- }
- public function getConnection() {
- return $this->connection;
- }
- public function getDatabase() {
- return $this->database;
- }
- }
- ======================================================================================================================================
- <?php
- /**
- * Created by PhpStorm.
- * User: Serenity
- * Date: 6-okt-2010
- * Time: 19:15:41
- * To change this template use File | Settings | File Templates.
- */
- class mysql_result {
- private $result;
- private $last_row;
- private $rowset;
- public function __construct($result) {
- if (!is_resource($result)) {
- throw new Exception('$result is not a valid resource');
- }
- $this->result = $result;
- }
- public function fetch() {
- $this->last_row = mysql_fetch_assoc($this->result);
- return $this->last_row;
- }
- public function next(){
- $this->fetch();
- }
- public function getRow(){
- return $this->last_row;
- }
- public function fetchField($field) {
- if (!is_array($this -> last_row))
- $this -> fetch();
- return strip_tags(stripslashes($this->last_row[$field]));
- }
- public function valid() {
- return $this -> current() != false;
- }
- public function current() {
- if (!is_array($this -> last_row))
- $this -> fetch();
- return $this -> last_row;
- }
- public function seek($id){
- if(!mysql_data_seek($this->result,$id))
- throw new Exception('invalid row');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement