Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("OBJECT", "object");
- define("ASSOC", "assoc");
- define("ARRAY", "array");
- class MySQL
- {
- private $host, $username, $password, $database, $statement;
- public $final;
- public static function __construct($host, $username, $password, $database)
- {
- $this->username = $username;
- $this->password = $password;
- $this->host = $host;
- $this->database = $database;
- $SQLServer = mysql_connect($this->host, $this->username, $this->password);
- mysql_select_db($this->database, $SQLServer);
- }
- public static function query($query)
- {
- return mysql_query($query);
- }
- public static function fetch($resultQuery, $type = "object")
- {
- if(isset($type))
- {
- switch($type)
- {
- case "object":
- return mysql_fetch_object($resultQuery);
- break;
- case "array":
- return mysql_fetch_array($resultQuery);
- break;
- case "assoc":
- return mysql_fetch_assoc($resultQuery);
- break;
- default:
- return mysql_fetch_object($resultQuery);
- }
- }
- else
- {
- return mysql_fetch_object($resultQuery);
- }
- }
- public static function counts($resultCount)
- {
- return mysql_num_rows($resultCount);
- }
- public static function error()
- {
- return mysql_error();
- }
- public static function errno()
- {
- if(mysql_errno())
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static function prepare($statement)
- {
- $this->statement = $statement;
- }
- public static function bind($inQuery, $value)
- {
- if(is_array($inQuery) && is_array($value))
- {
- if(count($inQuery) == count($value))
- {
- $finalQuery = array();
- for($x = 0; $x <= count($inQuery) - 1; $x++)
- {
- $finalQuery[$x] = str_replace($inQuery[$x], $value[$x], $this->statement);
- }
- }
- else
- {
- throw new Exception("Invalid array argument count for MySQL::bind.");
- }
- }
- else
- {
- $this->final = str_replace($inQuery, $value, $this->statement);
- }
- if(isset($finalQuery))
- {
- $this->final = end($finalQuery);
- }
- unset($this->statement);
- }
- public static function execute()
- {
- return $this->query($this->final);
- }
- }
Add Comment
Please, Sign In to add comment