Created
June 16, 2010 19:52
-
-
Save jamsesso/441171 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment