Well, I wanted to try something out and to test some stuff, and then I ended up writing this class.
It's completely unusable, well, at least, in the state it is in right now. But I pretty much feel great for writing it as I stumbled across some few points in PHP that I was weak at(arrays, specifically.).
So, yeah, here it is.
Example for usage:Code:<?php
/*--------------------------------------------
* @author: AUTHOR
* @framework-author: Omar Wael
*---------------------------------------------
********************USAGE*********************
* $_database['host'] = "OMAR-PC\SQLEXPRESS";
* $_database['user'] = "sa";
* $_database['pass'] = "password";
* $_database['dbn'] = "GunzDB";
*
*
* $db = new mssql();
*
* $db->executeQuery(array("AID", "UGradeID"), "Account", "WHERE AID IN (SELECT AID FROM Character WHERE Name = 'Vusion' AND DeleteFlag != 1)");
* echo $db->result();
* $db->disconnect();
* --------------------------------------------*/
class mssql
{
/* Variable holding the server name. */
var $host;
/* Variable holding the username. */
var $user;
/* Variable holding the password. */
var $pass;
/* Variable holding the database name. */
var $dbn;
/* Variable holding the database connection. */
var $link;
/* Boolean telling whether we're connected or not. */
var $isCon;
/* Variable holding the current class query object. */
var $classQuery;
/* Variable holding the rows selected in the current class query. */
private $queryRows;
/* Return array for the current class query. */
private $retArr = array();
public function __construct()
{
$this->host = $_database['host'];
$this->user = $_database['user'];
$this->pass = $_database['pass'];
$this->dbn = $_database['dbn'];
$this->connect();
}
public function connect()
{
$this->link = mssql_connect($this->host, $this->user, $this->pass) or die("Could not connect to MSSQL!");
$this->isCon = true;
$this->selectDatabase($this->dbn);
}
public function selectDatabase($dbn)
{
mssql_select_db($dbn, $this->link);
}
public function disconnect()
{
mssql_close($this->link);
$this->isCon = false;
}
public function executeQuery($rows, $table, $conditions = "")
{
if(!$this->isCon) return;
$this->queryRows = $rows;
$this->classQuery = mssql_query("SELECT ".((is_array($rows)) ? implode(", ", $rows) : $rows)." FROM ".$table." ".$conditions."");
}
public function result($method = "implode")
{
if(!isset($this->classQuery)) return;
if(mssql_num_rows($this->classQuery) < 1)
return false;
$fetch = mssql_fetch_array($this->classQuery);
for($i = 0; $i < ((is_array($this->queryRows)) ? count($this->queryRows) : 1); $i++)
array_push($this->retArr, $fetch[$i]);
if($method == "implode")
return ((is_array($this->queryRows)) ? implode(", ", $this->retArr) : implode("", $this->retArr));
else
return $this->retArr;
}
}
?>
Code:<?php
$_database['host'] = "OMAR-PC\SQLEXPRESS";
$_database['user'] = "sa";
$_database['pass'] = "mazemania1";
$_database['dbn'] = "GunzDB";
$db = new mssql();
$db->executeQuery(array("AID", "UGradeID"), "Account", "WHERE AID IN (SELECT AID FROM Character WHERE Name = 'Vusion' AND DeleteFlag != 1)");
echo $db->result();
$db->disconnect();
?>

