Mac
New Member
- Feb 9, 2011
- 111
- 2
PHP:
<?php
class MySQL {
public $host;
public $user;
public $pass;
public $dbname;
public function __construct($a, $b, $c, $d) {
if(isset($a, $b, $c, $d)):
$this->host = $a;
$this->user = $b;
$this->pass = $c;
$this->dbname = $d;
else:
throw new exception('Required fields are not set');
endif;
if(isset($this->host, $this->user, $this->pass, $this->dbname)):
mysql_connect($this->host, $this->user, $this->pass) or die(mysql_error());
mysql_select_db($this->dbname) or die(mysql_error());
else:
throw new exception('Required fields for MySQL connection or MySQL selecting db are not set');
endif;
}
public function makeQuery($e) {
if(isset($e)):
mysql_query($e);
else:
throw new exception('MySQL query is empty');
endif;
}
public function num_rows($f) {
if(isset($f)):
mysql_num_rows($f);
else:
throw new exception('MySQL num_rows function is empty');
endif;
}
public function mysql_array($g) {
if(isset($g)):
mysql_fetch_array($g);
else:
throw new exception('MySQL mysql_array function is empty');
endif;
}
public function escape_string($h) {
if(isset($h)):
mysql_escape_string($h);
else:
throw new exception('MySQL escape_string function is empty');
endif;
}
}
$mysql = new MySQL("localhost", "root", "pass", "dbname");