Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Copyright Slidefuse Networks 2012
- Author: Spencer Sharkey (spencer@sf-n.com)
- */
- class SFQL {
- public static $oCon;
- public $VERSION = "1.0";
- private static $bDebug = false;
- private static $sHost = "localhost";
- private static $sUsername = "";
- private static $sPassword = "";
- private static $sDatabase = "";
- private static $sBuffer = "";
- //A function called whent the Class is constructed
- public function __construct() {
- self::connect();
- }
- //A function to return the version.
- public static function getVersion() {
- return self::$VERSION;
- }
- //A function called to set the debug on or off.
- public static function setDebug($bToggle) {
- if ($bToggle === false or $bToggle === true) {
- self::$bDebug = $bToggle;
- } else {
- return false;
- }
- }
- //A function called to determine if debug mode is on.
- private static function isDebug() {
- return $bDebug;
- }
- //A private function to connect to the database.
- private static function connect() {
- self::$oCon = mysql_connect(self::$sHost, self::$sUsername, self::$sPassword);
- if (self::$oCon) {
- return mysql_select_db(self::$sDatabase, self::$oCon);
- } else {
- return false;
- }
- }
- //A function called to get the exception of the last MySQL call. If debug is on it'll automatically print it.
- public static function getException() {
- $sError = mysql_error(self::$oCon);
- if (self::isDebug() AND $sError != "") {
- echo "<br><b>SFQL Error!</b> $sError<br>";
- }
- return $sError or null;
- }
- //A function to run a clean query.
- public static function query($sQuery) {
- $sBuffer = $sQuery;
- $mQuery = mysql_query($sQuery);
- if (!$mQuery) {
- if (self::isDebug()) {
- self::getException();
- }
- return false;
- }
- return $mQuery;
- }
- //A function to return the amount of rows from a mysql query.
- public static function countRows($sQuery) {
- $mysqlQuery = self::query($sQuery);
- if ($mysqlQuery) {
- return mysql_num_rows($mysqlQuery);
- } else {
- return false;
- }
- }
- //A function to take a query, and get all the results.
- public static function queryArray($sQuery, $returnNumber = false) {
- $mysqlQuery = self::query($sQuery);
- if ($mysqlQuery) {
- $oList = array();
- $i = 0;
- while ($rowData = mysql_fetch_array($mysqlQuery)) {
- $oList[$i] = $rowData;
- $i++;
- }
- if (!$returnNumber) {
- return $oList;
- } else {
- return array($oList, $i);
- }
- } else {
- return false;
- }
- }
- //A function to take a query, and get the first result.
- public static function queryRow($sQuery) {
- $mysqlQuery = self::query($sQuery);
- if ($mysqlQuery) {
- $oList = array();
- $i = 0;
- while ($rowData = mysql_fetch_array($mysqlQuery)) {
- $oList[$i] = $rowData;
- $i++;
- }
- if ($i > 1) {
- if (self::isDebug()) {
- echo "<br><b>SFQL Error!</b> More than one row!<br>";
- }
- return false;
- } else {
- if ($i > 0) {
- return $oList[0];
- } else {
- return false;
- }
- }
- } else {
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment