mssql.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,425 行 · 第 1/4 页

PHP
1,425
字号
        $this->connected_user = $this->user;        $this->connected_password = $this->password;        $this->connected_port = $port;        $this->selected_database = $this->database_name;        $this->opened_persistent = $this->getoption('persistent');        return(MDB_OK);    }    // }}}    // {{{ _close()    /**     * all the RDBMS specific things needed close a DB connection     *     * @return boolean     * @access private     **/    function _close()    {        if ($this->connection != 0) {            if (isset($this->supported['Transactions']) && !$this->auto_commit) {                $result = $this->_doQuery("ROLLBACK TRANSACTION");            }            @mssql_close($this->connection);            $this->connection = 0;            $this->affected_rows = $this->current_row = -1;            if (isset($result) && MDB::isError($result)) {                return($result);            }            unset($GLOBALS['_MDB_databases'][$this->database]);            return(TRUE);        }        return(FALSE);    }    function standaloneQuery($query)    {        if(!PEAR::loadExtension($this->phptype)) {            return(PEAR::raiseError(NULL, MDB_ERROR_NOT_FOUND,                NULL, NULL, 'extension '.$this->phptype.' is not compiled into PHP',                'MDB_Error', TRUE));        }        $connection = @mssql_connect($this->host,$this->user,$this->password);        if($connection == 0) {            return($this->mssqlRaiseError(NULL, "Query: Could not connect to the Microsoft SQL server"));        }        $result = @mssql_query($query, $connection);        if(!$result) {            return($this->mssqlRaiseError(NULL, "Query: Could not query a Microsoft SQL server"));        }        @mssql_close($connection);        return(MDB_OK);    }    // }}}    // {{{ query()    /**     * Send a query to the database and return any results     *     * @access public     *     * @param string  $query  the SQL query     * @param mixed   $types  array that contains the types of the columns in     *                        the result set     *     * @return mixed a result handle or MDB_OK on success, a MDB error on failure     */    function query($query, $types = NULL)    {        $this->debug("Query: $query");        if ($this->database_name) {            $ismanip = MDB::isManip($query);            $this->last_query = $query;            $first = $this->first_selected_row;            $limit = $this->selected_row_limit;            $this->first_selected_row = $this->selected_row_limit = 0;            $last_connection = $this->connection;            $result = $this->connect();            if (MDB::isError($result)) {                return($result);            }            if($limit > 0) {                $fetch = $first + $limit;                if (!$ismanip) {                    $query = str_replace('SELECT', "SELECT TOP $fetch", $query);                }            }            if( $last_connection != $this->connection                || !strcmp($this->selected_database, '')                || strcmp($this->selected_database, $this->database_name))            {                if(!@mssql_select_db($this->database_name, $this->connection)) {                    return($this->mssqlRaiseError());                }            }            if ($result = $this->_doQuery($query)) {                if ($ismanip) {                    $this->affected_rows = @mssql_rows_affected($this->connection);                    return(MDB_OK);                } else {                    $result_value = intval($result);                    if($first > 0 || $limit > 0) {                        $this->limits[$result_value] = array($first, $limit);                    }                    $this->highest_fetched_row[$result_value] = -1;                    if ($types != NULL) {                        if (!is_array($types)) {                            $types = array($types);                        }                        $err = $this->setResultTypes($result, $types);                        if (MDB::isError($err)) {                            $this->freeResult($result);                            return($err);                        }                    }                    return($result);                }            }        }        return($this->mssqlRaiseError());    }    // }}}    // {{{ getColumnNames()    /**     * Retrieve the names of columns returned by the DBMS in a query result.     *     * @param resource   $result    result identifier     * @return mixed                an associative array variable     *                              that will hold the names of columns. The     *                              indexes of the array are the column names     *                              mapped to lower case and the values are the     *                              respective numbers of the columns starting     *                              from 0. Some DBMS may not return any     *                              columns when the result set does not     *                              contain any rows.     *     *                              a MDB error on failure     * @access public     */    function getColumnNames($result)    {        $result_value = intval($result);        if (!isset($this->highest_fetched_row[$result_value])) {            return($this->raiseError(MDB_ERROR_INVALID, NULL, NULL,                'Get column names: it was specified an inexisting result set'));        }        if (!isset($this->columns[$result_value])) {            $this->columns[$result_value] = array();            $columns = @mssql_num_fields($result);            for($column = 0; $column < $columns; $column++) {                $field_name = @mssql_field_name($result, $column);                if ($this->options['optimize'] == 'portability') {                    $field_name = strtolower($field_name);                }                $this->columns[$result_value][$field_name] = $column;            }        }        return($this->columns[$result_value]);    }    // }}}    // {{{ numCols()    /**     * Count the number of columns returned by the DBMS in a query result.     *     * @param resource    $result        result identifier     * @access public     * @return mixed integer value with the number of columns, a MDB error     *                       on failure     */    function numCols($result)    {        if (!isset($this->highest_fetched_row[intval($result)])) {            return($this->raiseError(MDB_ERROR_INVALID, NULL, NULL,                'numCols: it was specified an inexisting result set'));        }        return(@mssql_num_fields($result));    }    // }}}    // {{{ endOfResult()    /**    * check if the end of the result set has been reached    *    * @param resource    $result result identifier    * @return mixed TRUE or FALSE on sucess, a MDB error on failure    * @access public    */    function endOfResult($result)    {        $result_value = intval($result);        if (!isset($this->highest_fetched_row[$result_value])) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'End of result: attempted to check the end of an unknown result'));        }        return($this->highest_fetched_row[$result_value] >= $this->numRows($result)-1);    }    // }}}    // {{{ fetch()    /**    * fetch value from a result set    *    * @param resource    $result result identifier    * @param int    $row    number of the row where the data can be found    * @param int    $field    field number where the data can be found    * @return mixed string on success, a MDB error on failure    * @access public    */    function fetch($result, $row, $field)    {        $result_value = intval($result);        $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $row);        if (isset($this->limits[$result_value])) {            $row += $this->limits[$result_value][0];        }        $res = @mssql_result($result, $row, $field);        if ($res === FALSE && $res != NULL) {            return($this->mssqlRaiseError());        }        return($res);    }    // }}}    // {{{ fetchClob()    /**    * fetch a clob value from a result set    *    * @param resource    $result result identifier    * @param int    $row    number of the row where the data can be found    * @param int    $field    field number where the data can be found    * @return mixed content of the specified data cell, a MDB error on failure,    *               a MDB error on failure    * @access public    */    function fetchClob($result, $row, $field)    {        return($this->fetchLob($result, $row, $field));    }    // }}}    // {{{ fetchBlob()    /**    * fetch a blob value from a result set    *    * @param resource    $result result identifier    * @param int    $row    number of the row where the data can be found    * @param int    $field    field number where the data can be found    * @return mixed content of the specified data cell, a MDB error on failure    * @access public    */    function fetchBlob($result, $row, $field)    {        return($this->fetchLob($result, $row, $field));    }    // }}}    // {{{ convertResult()    /**    * convert a value to a RDBMS indepdenant MDB type    *    * @param mixed  $value   value to be converted    * @param int    $type    constant that specifies which type to convert to    * @return mixed converted value    * @access public    */    function convertResult($value, $type)    {        switch($type) {            case MDB_TYPE_BOOLEAN:                return ($value == '1') ? TRUE : FALSE;            case MDB_TYPE_DATE:                if(strlen($value) > 10) {                    $value=substr($value,0,10);                }                return($value);            case MDB_TYPE_TIME:                if(strlen($value) > 8) {                    $value=substr($value,11,8);                }                return($value);            case MDB_TYPE_TIMESTAMP:                return($value);            default:                return($this->_baseConvertResult($value,$type));        }    }    // }}}    // {{{ numRows()    /**    * returns the number of rows in a result object    *    * @param ressource $result a valid result ressouce pointer    * @return mixed MDB_Error or the number of rows    * @access public    */    function numRows($result)    {        $result_value = intval($result);        $rows = @mssql_num_rows($result);        if (isset($this->limits[$result_value])) {            $rows -= $this->limits[$result_value][0];            if ($rows < 0) $rows = 0;        }        return($rows);    }    // }}}    // {{{ freeResult()    /**     * Free the internal resources associated with $result.     *     * @param $result result identifier     * @return boolean TRUE on success, FALSE if $result is invalid     * @access public     */    function freeResult($result)    {        $result_value = intval($result);        if(isset($this->fetched_row[$result_value])) {            unset($this->fetched_row[$result_value]);        }        if(isset($this->highest_fetched_row[$result_value])) {            unset($this->highest_fetched_row[$result_value]);        }        if(isset($this->columns[$result_value])) {            unset($this->columns[$result_value]);        }        if(isset($this->result_types[$result_value])) {            unset($this->result_types[$result_value]);        }        return(@mssql_free_result($result));    }    // }}}    // {{{ getIntegerDeclaration()    /**     * Obtain DBMS specific SQL code portion needed to declare an integer type     * field to be used in statements like CREATE TABLE.     *     * @param string  $name   name the field to be declared.     * @param string  $field  associative array with the name of the properties

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?