/**
  * Devuelve el no error de MsSQL
  *
  * @return int
  */
 public function no_error()
 {
     if (!$this->id_connection) {
         return false;
     }
     return mssql_errno();
 }
 /**
  * Execute a batch query
  * @return mixed A database resource if successful, FALSE if not.
  */
 function queryBatch($abort_on_error = true, $p_transaction_safe = false)
 {
     $this->_errorNum = 0;
     $this->_errorMsg = '';
     if ($p_transaction_safe) {
         $si = mssql_get_server_info($this->_resource);
         preg_match_all("/(\\d+)\\.(\\d+)\\.(\\d+)/i", $si, $m);
         if ($m[1] >= 4) {
             $this->_sql = 'START TRANSACTION;' . $this->_sql . '; COMMIT;';
         } else {
             if ($m[2] >= 23 && $m[3] >= 19) {
                 $this->_sql = 'BEGIN WORK;' . $this->_sql . '; COMMIT;';
             } else {
                 if ($m[2] >= 23 && $m[3] >= 17) {
                     $this->_sql = 'BEGIN;' . $this->_sql . '; COMMIT;';
                 }
             }
         }
     }
     $query_split = preg_split("/[;]+/", $this->_sql);
     $error = 0;
     foreach ($query_split as $command_line) {
         $command_line = trim($command_line);
         if ($command_line != '') {
             $this->_cursor = mssql_query($command_line, $this->_resource);
             if (!$this->_cursor) {
                 $error = 1;
                 $this->_errorNum .= mssql_errno($this->_resource) . ' ';
                 $this->_errorMsg .= mssql_error($this->_resource) . " SQL={$command_line} <br />";
                 if ($abort_on_error) {
                     return $this->_cursor;
                 }
             }
         }
     }
     return $error ? false : true;
 }
 public function fetch_value($table, $field, $condition = null)
 {
     if (!$table || !$field) {
         exit("Arguments Missing !!");
     }
     $query = "select {$field} from {$table}";
     if ($condition != null) {
         $query = "select {$field} from {$table} where {$condition}";
     }
     $this->query = $query;
     $this->result = mssql_query($query) or $this->setError(mssql_error(), mssql_errno());
     if ($this->result) {
         $this->rows = intval(mssql_num_rows($this->result));
         $this->row = mssql_fetch_object($this->result);
         return $this->row->{$field};
     }
 }
Example #4
0
<?php

// Establish connection
$host = $PHPSPLOIT["HOST"];
$user = $PHPSPLOIT["USER"];
$pass = $PHPSPLOIT["PASS"];
$conn = @mssql_connect($host, $user, $pass);
if (!$conn) {
    return error("ERROR: %s: %s", @mssql_errno(), @mssql_error());
}
//@mssql_close($connect);
// NOTE:
// commented due to a bug in rare servers (bug found in iis6.0/php5.2.11)
return "OK";
 function loadMultipleV4(SelectStatement $statement, $typsicher = false)
 {
     #echo array_search("t1.".$statement->table[0], $statement->fields);
     unset($statement->fields[array_search("t1." . $statement->table[0] . "ID", $statement->fields)]);
     if (array_search("t1." . $statement->table[0] . "ID AS currentObjectID", $statement->fields) === false) {
         $statement->fields[] = "t1." . $statement->table[0] . "ID AS currentObjectID";
     }
     #print_r($statement->fields);
     #return ;
     if (count($statement->order) == 0) {
         $statement->order[] = "currentObjectID";
         $statement->orderAscDesc[] = "ASC";
     }
     $where = "(";
     $lastKey = "";
     $closeBrackets = "";
     foreach ($statement->whereFields as $key => $value) {
         $addOpenBracket = false;
         if ($where != "(" and $statement->whereBracketGroup[$lastKey] != $statement->whereBracketGroup[$key]) {
             $addOpenBracket = true;
             $where .= ")";
         }
         $currentWhereValue = $statement->whereValues[$key];
         if ($currentWhereValue != "NULL" and $currentWhereValue != "NOT NULL") {
             $currentWhereValue = "'" . mssql_real_escape_string($currentWhereValue) . "'";
         }
         $where .= ($where != "(" ? " " . $statement->whereLogOp[$key] . " " . ($addOpenBracket ? "(" : "") : "") . "[" . $statement->whereFields[$key] . "] " . $statement->whereOperators[$key] . " " . $currentWhereValue . "";
         $lastKey = $key;
     }
     $where .= ")";
     $order = "";
     foreach ($statement->order as $key => $value) {
         $order .= ($order != "" ? ", " : "") . "[" . $statement->order[$key] . "] " . $statement->orderAscDesc[$key];
     }
     $tables = array();
     for ($i = 0; $i < count($statement->joinTables); $i++) {
         if (!isset($tables[$statement->joinTables[$i]])) {
             $tables[$statement->joinTables[$i]] = array();
         }
         $tables[$statement->joinTables[$i]][] = array($statement->joinConditions[$i][0], $statement->joinConditionOperators[$i], $statement->joinConditions[$i][1]);
     }
     $t = 2;
     $joinAdd = "";
     foreach ($tables as $table => $conditions) {
         $ons = "";
         for ($i = 0; $i < count($conditions); $i++) {
             if ($i == 0) {
                 $ons .= ((!strpos($conditions[$i][0], ".") and $conditions[$i][0][0] != " ") ? "t1." : "") . "" . $conditions[$i][0] . " " . $conditions[$i][1] . " t{$t}." . $conditions[$i][2];
             } else {
                 if ($conditions[$i][2] != "NOT NULL" and $conditions[$i][2] != "NULL") {
                     $conditions[$i][2] = "'" . $conditions[$i][2] . "'";
                 }
                 $ons .= " AND t{$t}." . $conditions[$i][0] . " " . $conditions[$i][1] . " " . $conditions[$i][2] . "";
             }
         }
         $joinAdd .= "\n LEFT JOIN [" . $table . "] t{$t} ON({$ons})";
         $t++;
     }
     $sql = "WITH MSOrdered AS (\nSELECT\n (ROW_NUMBER() OVER(ORDER BY {$order})) - 1 AS MSZeilennummer, " . implode(",\n ", $statement->fields) . "\n FROM [" . $statement->table[0] . "] t1{$joinAdd} " . ($where != "()" ? "\n WHERE {$where}" : "") . (count($statement->group) > 0 ? "\n GROUP BY " . implode(", ", $statement->group) : "") . "\n)\n";
     #.(count($statement->limit) > 0 ? "\n LIMIT ".implode(", ",$statement->limit) : "")
     $sql .= "SELECT * FROM MSOrdered";
     $limit = array();
     if (isset($statement->limit[0])) {
         $limit = explode(",", $statement->limit[0]);
     }
     if (count($limit) == 1) {
         $sql .= " WHERE MSZeilennummer < " . $limit[0];
     }
     if (count($limit) == 2) {
         $sql .= " WHERE MSZeilennummer BETWEEN " . $limit[0] . " AND " . $limit[1];
     }
     $sql .= $order != "" ? "\n ORDER BY {$order}" : "";
     $collector = array();
     #if($statement->table[0] != "Userdata")
     $_SESSION["messages"]->startMessage("executing MSSQL: {$sql}");
     #echo nl2br($sql)."<br /><br />";
     $q = mssql_query($sql);
     #echo mssql_get_last_message().": ".(mssql_errno() == 208)."<br />";
     #if(mysql_error() AND (mysql_errno() == 1045 OR mysql_errno() == 2002)) throw new NoDBUserDataException();
     if (mssql_get_last_message() and mssql_errno() == 208) {
         throw new TableDoesNotExistException();
     }
     #if(mysql_error() AND mysql_errno() == 1046) throw new DatabaseNotSelectedException();
     #if(mysql_error() AND mysql_errno() == 1054) {
     #	preg_match("/[a-zA-Z0-9 ]*\'([a-zA-Z0-9\.]*)\'[a-zA-Z ]*\'([a-zA-Z ]*)\'.*/", mysql_error(), $regs);
     #	throw new FieldDoesNotExistException($regs[1],$regs[2]);
     #}
     #if(mysql_error()) echo "MySQL-Fehler: ".mysql_error()."<br />Fehlernummer: ".mysql_errno();
     if ($statement->table[0] != "Userdata") {
         $_SESSION["messages"]->endMessage(": " . mssql_rows_affected($this->connection) . " " . $statement->table[0] . " geladen");
     }
     if ($this->affectedRowsOnly) {
         $this->affectedRowsOnly = false;
         return mssql_rows_affected($this->connection);
     }
     if ($typsicher) {
         $types = array();
         $qc = mssql_query("SHOW COLUMNS FROM " . $statement->table[0]);
         while ($tc = mssql_fetch_object($qc)) {
             $types[$tc->Field] = $this->mysql2Object($tc->Type);
         }
         foreach ($statement->joinTables as $kc => $vc) {
             $qc = mssql_query("SHOW COLUMNS FROM " . $vc);
             while ($tc = mssql_fetch_object($qc)) {
                 $types[$tc->Field] = $this->mysql2Object($tc->Type);
             }
         }
         foreach ($statement->dataTypes as $kc => $vc) {
             $types = array_merge($types, $vc);
         }
     }
     $fields = null;
     while (@($t = mssql_fetch_object($q))) {
         $A = new Attributes();
         if ($fields == null) {
             $fields = PMReflector::getAttributesArrayAnyObject($t);
         }
         foreach ($fields as $key => $value) {
             $A->{$value} = $this->fixUtf8(stripslashes($t->{$value}));
             if ($typsicher) {
                 if (isset($types[$value])) {
                     $typObj = $types[$value];
                 } else {
                     throw new DataTypeNotDefinedException($value);
                 }
                 $A->{$value} = new $typObj($A->{$value});
                 #echo "<pre>";
                 #print_r($A);
                 #echo "</pre>";
             }
         }
         if (count($this->parsers) > 0) {
             foreach ($this->parsers as $key => $value) {
                 if (isset($A->{$key})) {
                     eval("\$A->\$key = " . $value . "(\"" . $A->{$key} . "\",\"load\");");
                 }
             }
         }
         $oID = "currentObjectID";
         $cName = $statement->table[0];
         $newCOfClass = new $cName($t->{$oID});
         $newCOfClass->setA($A);
         $collector[] = $newCOfClass;
     }
     return $collector;
 }
Example #6
0
 /**
  * Devuelve el no error de MsSQL
  *
  * @return int
  */
 public function no_error()
 {
     return mssql_errno();
 }
Example #7
0
 protected function throwMssqlException()
 {
     throw new jqGrid_Exception_DB(mssql_error(), null, mssql_errno());
 }