[PHPVortex-Commit] phpvortex DB_MSSQL.class.php,NONE,1.1 RS_MSSQL.class.php,NONE,1.1
Brought to you by:
nop144666
From: Thiago R. <nop...@us...> - 2005-03-21 21:00:58
|
Update of /cvsroot/phpvortex/phpvortex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9533 Added Files: DB_MSSQL.class.php RS_MSSQL.class.php Log Message: Added Microsoft SQL Server Connection Classes --- NEW FILE: DB_MSSQL.class.php --- <?php /** * File for class DB_MSSQL. * * @package Vortex * @subpackage DB * @author Thiago Ramon Gonçalves Montoya * @copyright Copyright 2004, Thiago Ramon Gonçalves Montoya * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License */ /** Require the base class */ require_once('DB_Base.class.php'); /** Require the RecordSet class header. */ require_once('RS_MSSQL.class.php'); /** * Class for MS SQL Server database connection. * * @package Vortex * @subpackage DB */ class DB_MSSQL extends DB_Base { /** * Open a new connection to the database if not already connected. * * @param bool $persist Open a persistent connection? * @return bool Returns TRUE if the connection was successfully established, FALSE if an error occurred. */ function Connect($persist=FALSE) { if (!is_null($this->link)) return FALSE; if ($persist) { $this->link = mssql_pconnect($this->server, $this->user, $this->pw); } else { $this->link = mssql_connect($this->server, $this->user, $this->pw); } if ($this->link !== FALSE) { if (mssql_select_db($this->db, $this->link)) { return TRUE; } mssql_close($this->link); } $this->link = NULL; return FALSE; } /** * Execute a query at the database. * * @param string $sql Query to run. * @return RS_Base Returns a RecordSet object if there is a result to the query or TRUE if it was successfull, FALSE if a error occurred. */ function &Query($sql) { $rs = mssql_query($sql,$this->link); if ($rs === FALSE) { return FALSE; } return new RS_MSSQL($this, $rs); } /** * Close the connection to the database if still connected. * * @return bool Returns TRUE if the connection was closed, FALSE if it failed. */ function Close() { if (mssql_close($this->link)) { $this->link = NULL; return TRUE; } return FALSE; } /** * Transactions: Begin a new transaction. * * @return bool Returns TRUE if the new transaction began, FALSE if it failed. */ function Begin() { return $this->Query('BEGIN TRANSACTION'); } /** * Transactions: Commit a transaction. * * @return bool Returns TRUE if the transaction was commited, FALSE if it failed. */ function Commit() { return $this->Query('COMMIT TRANSACTION'); } /** * Transactions: Rollback a transaction. * * @return bool Returns TRUE if the transaction was cancelled, FALSE if it failed. */ function Rollback() { return $this->Query('ROLLBACK TRANSACTION'); } /** * Process a string for safe use in a database insertion. * * @param string $data The string to be processed. * @return string Returns the processed string. */ function AddSlashes($data) { return addslashes($data); } } ?> --- NEW FILE: RS_MSSQL.class.php --- <?php /** * File for class RS_MSSQL. * * @package Vortex * @subpackage DB * @author Thiago Ramon Gonçalves Montoya * @copyright Copyright 2004, Thiago Ramon Gonçalves Montoya * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License */ /** Require the base class */ require_once('RS_Base.class.php'); /** * Class for MS SQL Server RecordSets. * * @package Vortex * @subpackage DB */ class RS_MSSQL extends RS_Base { /** * Get the count of rows in the RecordSet. * * @return int Returns the number of rows in the RecordSet. */ function RowCount() { return mssql_num_rows($this->result); } /** * Get a row from the RecordSet. * * Case $row is set, return that row, case else, return the next row. * * @param int $row Row to return, defaults to next. * @param int $type Type of array to return (RS_ROW_NUM | RS_ROW_ASSOC | RS_ROW_BOTH). * @return array Returns the row from the RecordSet, or FALSE if EOF. */ function Row($row = -1, $type = RS_ROW_ASSOC) { if ($row != -1) { if (!mssql_data_seek($this->result, $row)) return FALSE; $this->row = $row; } $this->row++; switch ($type) { case RS_ROW_NUM: return mssql_fetch_row($this->result); break; case RS_ROW_ASSOC: return mssql_fetch_assoc($this->result); break; case RS_ROW_BOTH: return mssql_fetch_array($this->result); break; } return FALSE; } /** * Go to a row int the RecordSet. * * @param int $row Row to go to. * @return bool Returns TRUE on success, FALSE if failed. */ function SetRow($row = 0) { if (!mssql_num_rows($this->result)) return FALSE; if (!mssql_data_seek($this->result, $row)) return FALSE; $this->row = $row; return TRUE; } /** * Get all rows from the RecordSet. * * @param int $type Type of array to return (RS_ROW_NUM | RS_ROW_ASSOC | RS_ROW_BOTH). * @return array Returns all the rows from the RecordSet. */ function All($type = RS_ROW_ASSOC) { $rows = array(); $this->SetRow(); while ($row = $this->Row(-1, $type)) $rows[] = $row; return $rows; } /** * Get the last auto-generated ID from the RecordSet. * * @return int Returns the last auto-generated ID from the RecordSet. */ function LastId() { $tmp = mssql_query("SELECT @@IDENTITY", $this->db->link); $id = mssql_result($tmp, 0, 0); mssql_free_result($tmp); return $id; } /** * Close the RecordSet and free the memory. * * @return bool Returns TRUE if the RecordSet was closed, FALSE if it failed. */ function Close() { return mssql_free_result($this->result); } } ?> |