Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MSSMySQLQuery
- {
- private $cRes;
- private $cQuery;
- private $cHasQuery;
- private $cResult;
- public function __construct(&$pRes, $pQuery = null, $pExec = false)
- {
- $this->setResource($pRes);
- $this->setQuery($pQuery);
- if ($pExec)
- {
- $this->execute();
- }
- }
- public function __destruct()
- {
- if ((null != $this->cResult) && is_resource($this->cResult))
- {
- mysql_free_result($this->cResult);
- }
- }
- public function setResource(&$pRes)
- {
- if (is_resource($pRes))
- {
- $this->cRes = $pRes;
- }
- }
- public function setQuery($pQuery)
- {
- if (null != $pQuery)
- {
- $this->cHasQuery = true;
- }
- else
- {
- $this->cHasQuery = false;
- }
- $this->cQuery = $pQuery;
- $this->cResult = null;
- }
- public function execute()
- {
- if ($this->cHasQuery)
- {
- $this->cResult = mysql_query($this->cQuery, $this->cRes);
- if ($this->cResult)
- {
- return true;
- }
- }
- return false;
- }
- public function result()
- {
- return $this->cResult;
- }
- public function select($pType = "assoc")
- {
- if ((null != $this->cResult) && is_resource($this->cResult))
- {
- $rows = array();
- switch (mysql_num_rows($this->cResult))
- {
- case 0:
- return false;
- break;
- default:
- if ("assoc" == $pType)
- {
- while ($row = mysql_fetch_assoc($this->cResult))
- {
- $rows[] = $row;
- }
- }
- elseif ("num" == $pType)
- {
- while ($row = mysql_fetch_row($this->cResult))
- {
- $rows[] = $row;
- }
- }
- else
- {
- while ($row = mysql_fetch_array($this->cResult))
- {
- $rows[] = $row;
- }
- }
- break;
- }
- return $rows;
- }
- return false;
- }
- public function affectedRows()
- {
- if ((null != $this->cResult) && is_resource($this->cResult))
- {
- return mysql_num_rows($this->cResult);
- }
- return mysql_affected_rows();
- }
- public function error()
- {
- return mysql_error($this->cRes);
- }
- }
- class MSSMySQL
- {
- private $cResource;
- private $cHost;
- private $cUser;
- private $cPassword;
- private $cDb;
- public function __construct($pHost = MYSQL_HOST, $pUser = MYSQL_USER, $pPassword = MYSQL_PWD, $pDb = MYSQL_DB, $pAutoConnect = false)
- {
- $this->cHost = $pHost;
- $this->cUser = $pUser;
- $this->cPassword = $pPassword;
- $this->cDb = $pDb;
- if ($pAutoConnect)
- {
- $this->connect();
- }
- }
- public function connect()
- {
- if ($this->cResource = mysql_connect($this->cHost, $this->cUser, $this->cPassword))
- {
- if (mysql_select_db($this->cDb, $this->cResource))
- {
- return true;
- }
- }
- return false;
- }
- public function __destruct()
- {
- if (is_resource($this->cResource))
- {
- mysql_close($this->cResource);
- }
- }
- public function query($pQuery, $pIsSelect = false)
- {
- if (is_resource($this->cResource))
- {
- $qry = new MSSMySQLQuery($this->cResource, $pQuery);
- if (!$qry->execute())
- {
- return $qry->error();
- }
- if ($pIsSelect)
- {
- return $qry->select();
- }
- return $qry->affectedRows();
- }
- }
- public function customQuery($pQuery)
- {
- return new MSSMySQLQuery($this->cResource, $pQuery);
- }
- public function error()
- {
- return mysql_error($this->cResource);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement