Source for file EDB_MSSQL.php
Documentation is available at EDB_MSSQL.php
* Project: EDB_MSSQL :: MSSQL abstraction layer
* File: EDB/EDB_MSSQL.php
* The EDB_MSSQL class is MSSQL abstraction layer that used internally
* @subpackage EDB_ABSTRACT
* @author JoungKyun.Kim <http://oops.org>
* @copyright (c) 2018, JoungKyun.Kim
* @link http://pear.oops.org/package/EDB
* MSSQL engine for EDB API
* This class support abstracttion DB layer for MSSQL Engine
* db handler of EDB_MSSQL class
* The number of query parameter
// {{{ (object) EDB_MSSQL::__construct ($host, $user, $pass, $db)
* Instantiates an EDB_MSSQL object and opens an MSSQL database
* $db = new EDB_MSSQL ('mssql://localhost', 'user', 'host', 'database');
* $db = new EDB_MSSQL ('mssql://localhost:33000', 'user', 'host', 'database');
* $db = new EDB_MSSQL ('mssql://localhost:33000?autocommit=false', 'user', 'host', 'database');
* If you add prefix 'p~' before host, you can connect with persistent
* $db = new EDB_MSSQL ('mssql://p~localhost', 'user', 'host', 'database');
* @param string $hostname MSSQL host
* @param string $user MSSQL user
* @param string $password MSSQL password
* @param string $database MSSQL database
$argv = is_array ($_argv[0]) ? $_argv[0] : $_argv;;
$iniset ('magic_quotes_sybase', 'Off');
throw new myException ('MSSQL extension is not loaded on PHP!', E_USER_ERROR);
$func = 'mssql_pconnect';
$this->db = $func ($o->host, $o->user, $o->pass);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_MSSQL::get_charset (void)
* Get character set of current database
* MSSQL extension don't support this function
* @return string Current character set name on DB
// {{{ (bool) EDB_MSSQL::set_charset ($charset)
* Set character set of current database
* This method is always returned true because MSSQL don't support
* @return bool always return true
* @param string name of character set that supported from database
// {{{ (string) EDB_MSSQL::escape ($string)
* Escape special characters in a string for use in an SQL statement
* @param string The string that is to be escaped.
// {{{ (int) EDB_MSSQL::query ($query, $param_type, $param1, $param2 ...)
* Performs a query on the database
* @return integer The number of affected rows or false
* @param string $query The query strings
* @param string $type (optional) Bind parameter type. See also
* @param mixed $param1 (optional) Bind parameter 1
* @param mixed $param2,... (optional) Bind parameter 2 ..
$argv = is_array ($_argv[0]) ? $_argv[0] : $_argv;;
// store query in log variable
if ( $this->pno++ == 0 ) // no bind query
$this->no_bind_query ($sql);
$this->bind_query ($sql, $argv);
if ( preg_match ('/^(update|insert|delete|replace)/i', trim ($sql)) ) {
/* Insert or update, or delete query */
// {{{ (string) EDB_MSSQL::lastId (void)
* 가장 마지막 입력 row의 OID를 반환한다.
if ( ($r = @mssql_query ('SELECT @@identity AS id')) === false )
// {{{ (bool) EDB_MSSQL::seek ($offset)
* Move the cursor in the result
* @param Number of units you want to move the cursor.
function seek ($offset) {
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (object) EDB_MSSQL::fetch (void)
* Fetch a result row as an associative object
* @return object|falseThe object of fetched a result row or false
* @param boolean (optional) 수행 후 result를 free 한다. 기본값: false
function fetch ($free = false) {
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (array) EDB_MSSQL::fetch_all ($free = true)
* Fetch all result rows as an associative object
* @return array The fetched object result rows
* @param boolean (optional) free result set after fetch.
while ( ($r = $this->fetch ()) !== false )
// {{{ (bool) EDB_MSSQL::free_result (void)
* Frees stored result memory for the given statement handle
if ( ! $this->free ) return true;
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_MSSQL::field_name ($index)
* Return the name of the specified field index
* @param integer The numerical field offset. The field_offset starts
* at 0. If field_offset does not exist, return false
* and an error of level E_WARNING is also issued.
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_MSSQL::field_type ($index)
* Get the type of the specified field in a result
* @param integer The numerical field offset. The field_offset starts
* at 0. If field_offset does not exist, return false
* and an error of level E_WARNING is also issued.
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (int) EDB_MSSQL::num_fields (void)
* Return the number of columns in the result set
* @return integer|falsereturn -1 if SQL sentence is not SELECT.
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (void) EDB_MSSQL::trstart (void)
$this->db->query ('BEGIN TRANSACTION');
// {{{ (void) EDB_MSSQL::trend ($v)
* @param bool false일경우 rollback을 수행한다.
function trend ($v = true) {
$sql = ($v === false) ? 'ROLLBACK' : 'COMMIT';
$this->db->query ($sql . ' TRANSACTION');
// {{{ (void) EDB_MSSQL::close (void)
// {{{ private (int) EDB_MSSQL::no_bind_query ($sql)
* Performs a query on the database
* @return integer The number of affected rows or false
* @param string The query strings
private function no_bind_query ($sql) {
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ private (int) EDB_MSSQL::bind_query ($sql, $parameters)
* Performs a bind query on the database
* mssql_bind api is supported stored procedure, so EDB
* package is supported by self bind method of EDB
* @return integer The number of affected rows or false
* @param string The query strings
* @param array (optional) Bind parameter type
private function bind_query ($sql, $params) {
if ( $this->pno != count ($params) || $this->check_param ($params) === false ) {
'Number of elements in query doesn\'t match number of bind variables',
$parano = strlen ($params[0]);
for ( $i= 0, $j= 1; $i< $parano; $i++ , $j++ ) {
switch ($params[0][$i]) {
$params[$j] = $params[$j]->data;
$params[$j] = 'unquote:' . $this->escape_bin ($params[$j]);
return $this->no_bind_query ($query);
// {{{ priavet (string) EDB_MSSQL::binary_escape ($string)
* Escape special characters in a string for use in an SQL statement
* @param string The string that is to be escaped.
private function escape_bin ($bin) {
} catch ( Exception $e ) { }
* vim: set filetype=php noet sw=4 ts=4 fdm=marker:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
|