public static function query($queryStr = '', $objectStr = '')
 {
     $queryDB = mssql_query(self::$dbConnect, $queryStr);
     if (preg_match('/insert into/i', $queryDB)) {
         mssql_next_result($queryDB);
         $row = mssql_fetch_row($queryDB);
         self::$insertID = $row[0];
     }
     if (is_object($objectStr)) {
         $objectStr($queryDB);
     }
     return $queryDB;
 }
Beispiel #2
0
 /**
  * Move the internal result pointer to the next available result
  *
  * @return true on success, false if there is no more result set or an error object on failure
  * @access public
  */
 function nextResult()
 {
     if ($this->result === false) {
         return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'resultset has already been freed', __FUNCTION__);
     } elseif (is_null($this->result)) {
         return false;
     }
     return @mssql_next_result($this->result);
 }
 /**
  * @see CallableStatement::getMoreResults()
  */
 function getMoreResults()
 {
     $this->rsFetchCount++;
     // we track this because
     $hasMore = mssql_next_result($this->result);
     if ($this->resultSet) {
         $this->resultSet->close();
     }
     if ($hasMore) {
         $clazz = $this->resultClass;
         $this->resultSet = new $clazz($this, $this->result);
     } else {
         $this->resultSet = null;
     }
     return $hasMore;
 }
Beispiel #4
0
 /**
  * Move the internal result pointer to the next available result
  * Currently not supported
  *
  * @return true if a result is available otherwise return false
  * @access public
  */
 function nextResult()
 {
     if (is_null($this->result)) {
         return $this->mdb->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'nextResult: resultset has already been freed');
     }
     return @mssql_next_result($this->result);
 }
Beispiel #5
0
 public function sqlReport($sQuery)
 {
     if (!preg_match('/^SELECT/', $sQuery)) {
         return '';
     }
     $bTable = false;
     $sHtml = '';
     @mssql_query('SET SHOWPLAN_TEXT ON;', $this->_hMaster);
     if ($hResult = @mssql_query($sQuery, $this->_hMaster)) {
         @mssql_next_result($hResult);
         while ($aRow = @mssql_fetch_row($hResult)) {
             list($bTable, $sData) = Phpfox_Debug::addRow($bTable, $aRow);
             $sHtml .= $sData;
         }
     }
     @mssql_query('SET SHOWPLAN_TEXT OFF;', $this->_hMaster);
     @mssql_free_result($hResult);
     if ($bTable) {
         $sHtml .= '</table>';
     }
     return $sHtml;
 }
Beispiel #6
0
 /**
  * 把查询数据库的指针移到下一条记录
  * 
  * @return array
  */
 function nextRecord()
 {
     $this->Record = array();
     mssql_next_result($this->queryId);
     $this->Record = mssql_fetch_array($this->queryId);
     $result = $this->Record;
     if (!is_array($result)) {
         return $this->Record;
     }
     foreach ($result as $key => $value) {
         $keylower = strtolower($key);
         if ($keylower != $key) {
             $this->Record[$keylower] = $value;
         }
     }
     return $this->Record;
 }
Beispiel #7
0
 /**
  * method to deal with the execution of MS SQL stored proceedured
  * @param $string $procName The name of the proceedure to execute
  * @param array $paramArray An array containing entries for each paramneeded but the stored proceedure see the exampel in the code below
  */
 function exeStoredProc($procName, $paramArray = false, $skip_results = false)
 {
     // example param array
     // $paramArray = array ('LocationName' => array ('VALUE' => 'the clients host name', 'TYPE' => 'SQLVARCHAR', 'ISOUTPUT' => 'false', 'IS_NULL' =>'false', 'MAXLEN' => '255' ) );
     // each element in the paramArray must idetify a paramiter required by the stored proceedure and can tain an array of settings from that paramiter
     // see http://php.net/manual/en/function.mssql-bind.php for information on the values for these paramiters
     // initiate the stored proceedure
     $stmt = mssql_init($procName, $this->linkid);
     // bind paramiters
     if ($paramArray) {
         foreach ($paramArray as $paramName => $values) {
             mssql_bind($stmt, $paramName, $values['VALUE'], $values['TYPE'], $values['ISOUTPUT'], $values['IS_NULL'], $values['MAXLEN']);
         }
     }
     // execute the stored proceedure
     $results = mssql_execute($stmt);
     // if we do not get anu results return false
     if (!$results) {
         return false;
         // if we get results then put them in to an array and return it
     } else {
         // define the array to return
         $resultArray = array();
         // loop throught he result set and place each result to the resultArray
         do {
             while ($row = mssql_fetch_row($stmt)) {
                 $resultArray[] = $row;
             }
         } while (mssql_next_result($stmt));
         // clean up the statment ready for the next useexec SELLING_GetLocation @LocationName='it-leigh.skilouise.com'
         mssql_free_statement($stmt);
         //returnt he result array
         return $resultArray;
     }
 }
Beispiel #8
0
 function NextRecordSet()
 {
     if (!mssql_next_result($this->_queryID)) {
         return false;
     }
     $this->_inited = false;
     $this->bind = false;
     $this->_currentRow = -1;
     $this->Init();
     return true;
 }
Beispiel #9
0
 /**
  * Move the internal result pointer to the next result
  * 
  * @param	resource	$statement - The result resource that is being evaluated.
  * @return	boolean
  */
 public function nextResult($statement)
 {
     if (!is_resource($statement)) {
         throw new LikePDOException("There is no active statement");
         return false;
     } else {
         return mssql_next_result($statement);
     }
 }
Beispiel #10
0
 function GetResults()
 {
     $out = array();
     do {
         while ($row = mssql_fetch_assoc($this->Result)) {
             $out[] = $row;
         }
     } while (mssql_next_result($this->Result));
     return $out;
 }
 /**
  * 把查询数据库的指针移到下一条记录
  *
  * @return array
  */
 public function nextRecord()
 {
     mssql_next_result($this->queryId);
     return mssql_fetch_array($this->queryId);
 }
Beispiel #12
0
SET @limit = 20
SET @offset = 4
OPEN Search
FETCH ABSOLUTE @offset FROM Search
WHILE @@FETCH_STATUS =0 AND @limit > 1
BEGIN
  FETCH NEXT FROM Search
  SET @limit = @limit -1
END
CLOSE Search
DEALLOCATE Search
EOSQL;
$num_rows = 0;
$res = mssql_query($sql) or die("query");
$row = mssql_fetch_assoc($res);
while ($row) {
    ++$num_rows;
    //  print_r($row);
    echo "got a row, name is {$row['name']}\n";
    $row = mssql_fetch_assoc($res);
    if (!$row) {
        if (mssql_next_result($res)) {
            $row = mssql_fetch_assoc($res);
        }
    }
}
if ($num_rows < 2) {
    echo "Expected more than a row\n";
    exit(1);
}
exit(0);
Beispiel #13
0
 /**
  * 向下移动一个数据集 Move the internal result pointer to the next result
  *
  * @return boolean The function will return TRUE if an additional result set was available or FALSE otherwise.
  */
 public function next_result()
 {
     if (!is_resource($this->result)) {
         return false;
     }
     mssql_next_result($this->result);
 }
Beispiel #14
0
 /**
  * Retrieves the next rowset (result set) for a SQL statement that has
  * multiple result sets.  An example is a stored procedure that returns
  * the results of multiple queries.
  *
  * @return bool
  * @throws Zend_Db_Statement_Exception
  */
 public function nextRowset()
 {
     if (mssql_next_result($this->_result) === false) {
         throw new Zend_Db_Statement_Exception(mssql_get_last_message());
     }
     // reset column keys
     $this->_keys = null;
     return true;
 }
Beispiel #15
0
function func_mssql_query($query, $sess, &$bin, &$biVal, &$biLen, &$biRes, &$biType)
{
    if (count($bin) >= 1) {
        $res = mssql_init($query);
        for ($i = 0; $i < count($bin); $i++) {
            $TypeParam = TRUE;
            $biRes[$i] = $biVal[$i];
            if ($biLen[$i] == -1) {
                $TypeParam = FALSE;
            }
            if ($biType[$i] == 1) {
                $msType = SQLVARCHAR;
            }
            if ($biType[$i] == 2) {
                $msType = SQLINT4;
            }
            if ($biType[$i] == 3) {
                $msType = SQLFLT8;
            }
            if ($biType[$i] == 4) {
                $msType = SQLVARCHAR;
            }
            mssql_bind($res, $bin[$i], $biRes[$i], $msType, $TypeParam);
        }
        $resExec = mssql_execute($res);
        while (mssql_next_result($resExec)) {
        }
    } else {
        $resExec = mssql_query($query);
        if (!$resExec) {
            ErreurExecutionMSSQL();
        }
    }
    return $resExec;
}
Beispiel #16
0
$num_res = 0;
$stmt = mssql_init("sp_php_test", $conn);
$rs = mssql_execute($stmt);
if (is_resource($rs)) {
    echo "fetching...\n";
    do {
        ++$num_res;
        echo "Processing result {$num_res}\n";
        echo "Num rows = " . mssql_num_rows($rs) . "\n";
        if (!$err && $num_res == 1 && mssql_num_rows($rs) != 0) {
            $err = "Expected 0 rows from recordset {$num_res}";
        }
        if (!$err && $num_res == 2 && mssql_num_rows($rs) != 2) {
            $err = "Expected 2 rows from recordset {$num_res}";
        }
        // Process result
    } while (mssql_next_result($rs));
    mssql_free_result($rs);
}
if (!$err && $num_res != 2) {
    $err = "Expected 2 resultset got {$num_res}";
}
# cleanup
mssql_query("drop proc sp_php_test");
mssql_query("drop table php_test");
mssql_close($conn);
if ($err) {
    echo "{$err}\n";
    exit(1);
}
exit(0);
Beispiel #17
0
 /**
  * Build db-specific report
  * @access private
  */
 function _sql_report($mode, $query = '')
 {
     switch ($mode) {
         case 'start':
             $html_table = false;
             @mssql_query('SET SHOWPLAN_TEXT ON;', $this->db_connect_id);
             if ($result = @mssql_query($query, $this->db_connect_id)) {
                 @mssql_next_result($result);
                 while ($row = @mssql_fetch_row($result)) {
                     $html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
                 }
             }
             @mssql_query('SET SHOWPLAN_TEXT OFF;', $this->db_connect_id);
             @mssql_free_result($result);
             if ($html_table) {
                 $this->html_hold .= '</table>';
             }
             break;
         case 'fromcache':
             $endtime = explode(' ', microtime());
             $endtime = $endtime[0] + $endtime[1];
             $result = @mssql_query($query, $this->db_connect_id);
             while ($void = @mssql_fetch_assoc($result)) {
                 // Take the time spent on parsing rows into account
             }
             @mssql_free_result($result);
             $splittime = explode(' ', microtime());
             $splittime = $splittime[0] + $splittime[1];
             $this->sql_report('record_fromcache', $query, $endtime, $splittime);
             break;
     }
 }
 /**
  * return the result of the last query.
  * @param mixed $idname if $idname is false keys are simply incrementing from 0, if $idname is string the key is the value of the column specified in the string
  */
 private function &lastResult($idnames = false)
 {
     do {
         $result = array();
         if (@mssql_num_rows($this->result) > 0) {
             if ($idnames === false) {
                 while ($row = mssql_fetch_assoc($this->result)) {
                     $result[] = $row;
                 }
             } else {
                 while ($row = mssql_fetch_assoc($this->result)) {
                     $current =& $result;
                     foreach ($idnames as $idname) {
                         if (!array_key_exists($idname, $row)) {
                             throw new InvalidArgumentException('Cant order result by a field thats not in the resultset (forgot to select it?)');
                         }
                         if ($row[$idname] === null) {
                             $row[$idname] = 'null';
                         }
                         $current =& $current[$row[$idname]];
                     }
                     $current = $row;
                 }
                 //while
             }
             //idnames!=false
         }
         //num_rows>0
     } while (mssql_next_result($this->result));
     return $result;
 }
 /**
  * Move the internal mssql result pointer to the next available result
  *
  * @param a valid fbsql result resource
  *
  * @access public
  *
  * @return true if a result is available otherwise return false
  */
 function nextResult($result)
 {
     return @mssql_next_result($result);
 }
Beispiel #20
0
 /**
  * Build db-specific report
  * @access: private
  */
 function _sql_report($mode, $query = '')
 {
     switch ($mode) {
         case 'start':
             $explain_query = $query;
             if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) {
                 $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
             } else {
                 if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) {
                     $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
                 }
             }
             if (preg_match('/^SELECT/', $explain_query)) {
                 $html_table = false;
                 @mssql_query("SET SHOWPLAN_TEXT ON;", $this->db_connect_id);
                 if ($result = @mssql_query($explain_query, $this->db_connect_id)) {
                     @mssql_next_result($result);
                     while ($row = @mssql_fetch_row($result)) {
                         $html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
                     }
                 }
                 @mssql_query("SET SHOWPLAN_TEXT OFF;", $this->db_connect_id);
                 @mssql_free_result($result);
                 if ($html_table) {
                     $this->html_hold .= '</table>';
                 }
             }
             break;
         case 'fromcache':
             $endtime = explode(' ', microtime());
             $endtime = $endtime[0] + $endtime[1];
             $result = @mssql_query($query, $this->db_connect_id);
             while ($void = @mssql_fetch_assoc($result)) {
                 // Take the time spent on parsing rows into account
             }
             @mssql_free_result($result);
             $splittime = explode(' ', microtime());
             $splittime = $splittime[0] + $splittime[1];
             $this->sql_report('record_fromcache', $query, $endtime, $splittime);
             break;
     }
 }