Guest User

Untitled

a guest
Jun 7th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1. <?php
  2. /*
  3.     Copyright Slidefuse Networks 2012
  4.     Author: Spencer Sharkey (spencer@sf-n.com)
  5. */
  6. class SFQL {
  7.    
  8.     public static $oCon;
  9.  
  10.     public $VERSION = "1.0";
  11.    
  12.     private static $bDebug = false;
  13.     private static $sHost = "localhost";
  14.     private static $sUsername = "";
  15.     private static $sPassword = "";
  16.     private static $sDatabase = "";
  17.    
  18.     private static $sBuffer = "";
  19.    
  20.     //A function called whent the Class is constructed
  21.     public function __construct() {
  22.         self::connect();
  23.     }
  24.    
  25.     //A function to return the version.
  26.     public static function getVersion() {
  27.         return self::$VERSION;
  28.     }
  29.    
  30.     //A function called to set the debug on or off.
  31.     public static function setDebug($bToggle) {
  32.         if ($bToggle === false or $bToggle === true) {
  33.             self::$bDebug = $bToggle;
  34.         } else {
  35.             return false;
  36.         }
  37.     }
  38.    
  39.     //A function called to determine if debug mode is on.
  40.     private static function isDebug() {
  41.         return $bDebug;
  42.     }
  43.    
  44.     //A private function to connect to the database.
  45.     private static function connect() {
  46.         self::$oCon = mysql_connect(self::$sHost, self::$sUsername, self::$sPassword);
  47.         if (self::$oCon) {
  48.             return mysql_select_db(self::$sDatabase, self::$oCon);
  49.         } else {
  50.             return false;
  51.         }
  52.     }
  53.    
  54.     //A function called to get the exception of the last MySQL call. If debug is on it'll automatically print it.
  55.     public static function getException() {
  56.         $sError = mysql_error(self::$oCon);
  57.         if (self::isDebug() AND $sError != "") {
  58.             echo "<br><b>SFQL Error!</b> $sError<br>";
  59.         }
  60.         return $sError or null;
  61.     }
  62.    
  63.     //A function to run a clean query.
  64.     public static function query($sQuery) {
  65.         $sBuffer = $sQuery;
  66.         $mQuery = mysql_query($sQuery);
  67.         if (!$mQuery) {
  68.             if (self::isDebug()) {
  69.                 self::getException();
  70.             }
  71.             return false;
  72.         }
  73.         return $mQuery;
  74.     }
  75.    
  76.     //A function to return the amount of rows from a mysql query.
  77.     public static function countRows($sQuery) {
  78.         $mysqlQuery = self::query($sQuery);
  79.         if ($mysqlQuery) {
  80.             return mysql_num_rows($mysqlQuery);
  81.         } else {
  82.             return false;
  83.         }
  84.     }
  85.    
  86.     //A function to take a query, and get all the results.
  87.     public static function queryArray($sQuery, $returnNumber = false) {
  88.         $mysqlQuery = self::query($sQuery);
  89.         if ($mysqlQuery) {
  90.             $oList = array();
  91.             $i = 0;
  92.             while ($rowData = mysql_fetch_array($mysqlQuery)) {
  93.                 $oList[$i] = $rowData;
  94.                 $i++;
  95.             }
  96.            
  97.             if (!$returnNumber) {
  98.                 return $oList;
  99.             } else {
  100.                 return array($oList, $i);
  101.             }
  102.         } else {
  103.             return false;
  104.         }
  105.     }
  106.    
  107.     //A function to take a query, and get the first result.
  108.     public static function queryRow($sQuery) {
  109.         $mysqlQuery = self::query($sQuery);
  110.         if ($mysqlQuery) {
  111.             $oList = array();
  112.             $i = 0;
  113.             while ($rowData = mysql_fetch_array($mysqlQuery)) {
  114.                 $oList[$i] = $rowData;
  115.                 $i++;
  116.             }
  117.            
  118.             if ($i > 1) {
  119.                 if (self::isDebug()) {
  120.                     echo "<br><b>SFQL Error!</b> More than one row!<br>";
  121.                 }
  122.                 return false;
  123.             } else {
  124.                 if ($i > 0) {
  125.                     return $oList[0];
  126.                 } else {
  127.                     return false;
  128.                 }
  129.             }
  130.         } else {
  131.             return false;
  132.         }
  133.     }
  134.        
  135. }
Add Comment
Please, Sign In to add comment