/**
  * @param $sql
  *
  * @return array
  */
 public function query($sql)
 {
     //
     $this->connection = $this->getConnection();
     // Run query
     $query = mssql_query($sql, $this->connection);
     // On error
     if ($query === false) {
         Response::error(500, $_SERVER["SERVER_PROTOCOL"] . ' DB query failed (SQL): ' . mssql_get_last_message());
     }
     // E.g. boolean is returned if no rows (e.g. no resource found or on UPDATE)
     if ($query === true) {
         $response = $query;
     } else {
         // Response
         $response = array();
         //
         // Loop rows and add to response array
         if (mssql_num_rows($query) > 0) {
             while ($row = mssql_fetch_assoc($query)) {
                 $response[] = $row;
             }
         }
         // Free the query result
         mssql_free_result($query);
     }
     // Close link
     $this->closeConnection();
     //
     return $response;
 }
 public function closeCursor()
 {
     if ($this->_result) {
         mssql_free_result($this->_result);
         $this->_result = false;
     }
 }
Beispiel #3
0
function econnect_copy($sql, $key, $node)
{
    global $old_gp;
    global $new_gp;
    $name = "";
    $inc = 0;
    $break = 0;
    $st_proc = "";
    $rset = mssql_query($sql, $old_gp);
    while ($line = mssql_fetch_assoc($rset)) {
        $st_proc = "";
        $break = 0;
        for ($inc = 0; $inc < mssql_num_fields($rset); $inc++, $break++) {
            $name = trim(mssql_field_name($rset, $inc));
            if ($break > 1) {
                $st_proc .= "\n   ";
                $break = 0;
            }
            $st_proc .= "@I_v{$name}='" . str_replace("'", "''", trim($line[$name])) . "', ";
        }
        $st_proc = "\n declare @O_iErrorState int; declare @oErrString varchar(255); \n select @O_iErrorState = 0;\n exec {$node}\n   {$st_proc} @oErrString = @oErrString output,@O_iErrorState = @O_iErrorState output;\n select @O_iErrorState as ret_val, ErrorDesc from  DYNAMICS..taErrorCode where errorcode = @O_iErrorState;\n ";
        #PHP bug fix work around
        $st_proc = str_replace("@I_vUnrealized_Purchase_Price_Vari=", "@I_vUnrealized_Purchase_Price_Variance_Acct=", $st_proc);
        echo "{$node} " . trim($line[$key]) . ". ";
        $rset_x = mssql_query($st_proc, $new_gp);
        $line_x = mssql_fetch_assoc($rset_x);
        if ($line_x["ret_val"] == 0) {
            echo "Successful.\n";
        } else {
            echo "Failed. Reason: " . trim($line_x["ErrorDesc"]) . "\n{$st_proc}\n";
            #exit();
        }
        mssql_free_result($rset_x);
    }
}
Beispiel #4
0
 private function executeQuery()
 {
     $return = false;
     if ($this->queryType == 'other') {
         if (mssql_query($this->query, $this->link) === true) {
             $return = true;
             $this->error = mssql_get_last_message();
         }
     } else {
         if ($result = mssql_query($this->query, $this->link)) {
             // Conteo de registros
             if ($this->queryType == 'insert' || $this->queryType == 'update' || $this->queryType == 'delete') {
                 $this->numRows = mssql_rows_affected($this->link);
                 $return = true;
             } else {
                 $this->numRows = mssql_num_rows($result);
                 $fetchType = MSSQL_NUM;
                 if ($this->queryReturn == 'assoc') {
                     $fetchType = MSSQL_ASSOC;
                 } elseif ($this->queryReturn == 'both') {
                     $fetchType = MSSQL_BOTH;
                 }
                 $return = array();
                 while ($row = mssql_fetch_array($result, $fetchType)) {
                     array_push($return, $row);
                 }
             }
             $this->error = mssql_get_last_message();
             mssql_free_result($result);
         } else {
             $this->error = mssql_get_last_message();
         }
     }
     return $return;
 }
 function free_result()
 {
     if (is_resource($this->result_id)) {
         mssql_free_result($this->result_id);
         $this->result_id = FALSE;
     }
 }
Beispiel #6
0
 /**
  * This function frees the command reference.
  *
  * @access public
  * @override
  */
 public function free()
 {
     if ($this->command !== NULL) {
         @mssql_free_result($this->command);
         $this->command = NULL;
         $this->record = FALSE;
     }
 }
 function free_result()
 {
     if ($this->Query_ID) {
         mssql_free_result($this->Query_ID);
     }
     $this->Query_ID = 0;
     $this->VEOF = -1;
 }
 public function close()
 {
     if ($this->rsrc) {
         mssql_free_result($this->rsrc);
         $this->rsrc = null;
     }
     $this->current = null;
 }
Beispiel #9
0
 public function getLastId()
 {
     $last_id = false;
     $resource = mssql_query("SELECT @@identity AS id", $this->link);
     if ($row = mssql_fetch_row($resource)) {
         $last_id = trim($row[0]);
     }
     mssql_free_result($resource);
     return $last_id;
 }
 function getOneColumnAsArray()
 {
     $column = array();
     $queryId = $this->connection->execute($this->getSQL());
     while (is_array($row = mssql_fetch_row($queryId))) {
         $column[] = is_numeric($row[0]) ? $row[0] : mb_convert_encoding($row[0], 'UTF-8', 'Windows-1251');
     }
     mssql_free_result($queryId);
     return $column;
 }
Beispiel #11
0
 public function exec(&$statement)
 {
     if ($result = @mssql_query($statement, $this->link)) {
         if (is_resource($result)) {
             mssql_free_result($result);
             return 0;
         }
         return mssql_rows_affected($this->link);
     }
     return false;
 }
 function loadTables()
 {
     if ($this->isExisting && !$this->isTablesLoaded) {
         $queryId = $this->connection->execute("select TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where TABLE_CATALOG='" . $this->name . "'");
         while (is_array($row = mssql_fetch_row($queryId))) {
             $this->tables[$row[0]] = null;
         }
         mssql_free_result($queryId);
         $this->isTablesLoaded = true;
     }
 }
Beispiel #13
0
 public function getNamaBulanById($id)
 {
     $sql = 'SELECT Bulan FROM ' . $this->table . ' WHERE BulanId=' . $id;
     $result = mssql_query($sql);
     if (mssql_num_rows($result) > 0) {
         while ($val = mssql_fetch_assoc($result)) {
             $namaBulan = $val['Bulan'];
         }
     }
     mssql_free_result($result);
     return $bulan;
 }
 public function getKecamatanByKelurahan($id)
 {
     $sql = 'SELECT a.Nama, a.KecamatanId, a.KodeDepdagri FROM ' . $this->table . ' a INNER JOIN M_Kelurahan b on a.KecamatanId=b.KecamatanId WHERE b.KelurahanId=' . $id;
     $result = mssql_query($sql);
     $data = array();
     if (mssql_num_rows($result) > 0) {
         while ($val = mssql_fetch_assoc($result)) {
             $data[] = array('KecamatanId' => $val['KecamatanId'], 'Nama' => $val['Nama'], 'KodeDedagri' => $val['KodeDepdagri']);
         }
     }
     mssql_free_result($result);
     return $data;
 }
 public function getAlasanTidakKbById($id)
 {
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE ID=' . $id;
     $result = mssql_query($sql);
     $data = array();
     if (mssql_num_rows($result) > 0) {
         while ($val = mssql_fetch_assoc($result)) {
             $data[] = array('ID' => $val['ID'], 'Alasan' => $val['Alasan'], 'SortNumber' => $val['SortNumber'], 'IsActive' => $val['IsActive']);
         }
     }
     mssql_free_result($result);
     return $data;
 }
Beispiel #16
0
 function _select($query)
 {
     // echo $query."<BR>";
     if ($result = mssql_query($query, $this->_LINK)) {
         $trow = array();
         while ($row = mssql_fetch_array($result)) {
             $trow[] = $row;
         }
         mssql_free_result($result);
         return count($trow) > 0 ? $trow : false;
     }
     return false;
 }
 public function getAllRecord()
 {
     $sql = 'SELECT * FROM ' . $this->table . ' ORDER BY TempatPelayananKBId';
     $result = mssql_query($sql);
     $data = array();
     if (mssql_num_rows($result) > 0) {
         while ($val = mssql_fetch_assoc($result)) {
             $data[] = array('TempatPelayananKBId' => $val['TempatPelayananKBId'], 'Nama' => $val['Nama']);
         }
     }
     mssql_free_result($result);
     return $data;
 }
Beispiel #18
0
 public function getRwByKelurahan($id)
 {
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE KelurahanId=' . $id;
     $result = mssql_query($sql);
     $data = array();
     if (mssql_num_rows($result) > 0) {
         while ($val = mssql_fetch_assoc($result)) {
             $data[] = array('RWId' => $val['RWId'], 'Nama' => $val['Nama'], 'KelurahanId' => $val['KelurahanId']);
         }
     }
     mssql_free_result($result);
     return $data;
 }
Beispiel #19
0
 /**
  * Performs an SQL query.
  *
  * @param  string  $query
  * @param  mixed   $limit
  * @param  boolean $warnOnFailure
  * @access public
  */
 function query($query, $limit = false, $warnOnFailure = true)
 {
     if ($limit != false) {
         $query = str_replace('SELECT', 'SELECT TOP ' . $limit, $query);
     }
     if ($this->config['debug_level'] > 1) {
         $this->debugQuery($query);
     }
     @mssql_free_result($this->result);
     $this->result = @mssql_query($query, $this->connection);
     if (!$this->result && $warnOnFailure) {
         phpOpenTracker::handleError('Database query failed.', E_USER_ERROR);
     }
 }
Beispiel #20
0
 public function query($sql)
 {
     LogMaster::log($sql);
     $res = mssql_query($sql, $this->connection);
     if ($this->insert_operation) {
         $last = mssql_fetch_assoc($res);
         $this->last_id = $last["dhx_id"];
         mssql_free_result($res);
     }
     if ($this->start_from) {
         mssql_data_seek($res, $this->start_from);
     }
     return $res;
 }
Beispiel #21
0
function tmssql()
{
    print "<h3>mssql</h3>";
    $db = mssql_connect('JAGUAR\\vsdotnet', 'adodb', 'natsoft') or die('No Connection');
    mssql_select_db('northwind', $db);
    $rs = mssql_query('select getdate() as date', $db);
    $o = mssql_fetch_row($rs);
    print_r($o);
    mssql_free_result($rs);
    print "<p>Delete</p>";
    flush();
    $rs2 = mssql_query('delete from adoxyz', $db);
    $p = mssql_num_rows($rs2);
    mssql_free_result($rs2);
}
Beispiel #22
0
 /**
  * 按SQL语句获取记录结果,返回数组
  * 
  * @param sql  执行的SQL语句
  */
 public function getArray($sql)
 {
     if (!($result = $this->exec($sql))) {
         return array();
     }
     if (!mssql_num_rows($result)) {
         return array();
     }
     $rows = array();
     while ($rows[] = mssql_fetch_array($result, MSSQL_ASSOC)) {
     }
     mssql_free_result($result);
     array_pop($rows);
     return $rows;
 }
Beispiel #23
0
 function close()
 {
     global $res, $databaseType;
     if ($databaseType == "mysql") {
         @mysql_free_result($this->index);
         @mysql_close($res);
     }
     if ($databaseType == "postgresql") {
         @pg_free_result($this->index);
         @pg_close($res);
     }
     if ($databaseType == "sqlserver") {
         @mssql_free_result($this->index);
         @mssql_close($res);
     }
 }
Beispiel #24
0
 public function execute($sql, $bindParams = array(), $additionalParameters = array())
 {
     $sql = $this->bind($sql, $bindParams);
     if ($result = mssql_query($sql, $this->connection)) {
         $rows = array();
         if (is_resource($result)) {
             while ($row = mssql_fetch_assoc($result)) {
                 $rows[] = $row;
             }
             mssql_free_result($result);
             $this->affectedRows = 0;
         } else {
             $this->affectedRows = mssql_rows_affected($this->connection);
         }
         return empty($rows) ? null : $rows;
     } else {
         $this->executeError($sql);
     }
 }
Beispiel #25
0
function ReaPaises($nIdPais)
{
    $sp = mssql_init('REAPAISES');
    //SP
    //Parámetros SP
    mssql_bind($sp, '@nIdPais', $nIdPais, SQLINT4);
    $resultado = mssql_execute($sp);
    //Ejecución SP
    $i = 0;
    while ($row = mssql_fetch_array($resultado)) {
        $html[$i]['id_pais'] = $row[0];
        $html[$i]['nombre'] = $row[1];
        $i++;
    }
    return $html;
    mssql_free_result($resultado);
    //Liberación del recurso
    mssql_free_statement($sp);
    //Liberación del recurso
}
Beispiel #26
0
function get_mssql_table($table, $dbconfig)
{
    $link = mssql_connect($dbconfig['hostname'], $dbconfig['username'], $dbconfig['password']);
    if (!$link || !mssql_select_db($dbconfig['database'], $link)) {
        die('<div class="alert alert-danger"><strong>Ошибка подключения к БД.</strong> Проверьте параметры соединения в файле config.php.</div>');
    }
    if ($result = mssql_query("SELECT * FROM " . $table, $link)) {
        $table_code = '';
        while ($row = mssql_fetch_assoc($result)) {
            $table_code = $table_code . '<tr>' . "\r\n";
            foreach ($row as $key => $value) {
                $table_code = $table_code . '<td>' . $value . '</td>' . "\r\n";
            }
            $table_code = $table_code . '</tr>' . "\r\n";
        }
        mssql_free_result($result);
    } else {
        $table_code = '';
    }
    mssql_close($link);
    return $table_code;
}
Beispiel #27
0
 function &executeQuery($query, $interrupt = true, $raw = false)
 {
     $result = null;
     if ($this->link != null && $this->dbsel != null) {
         if (is_array(MSSQL_Connector::$traza)) {
             MSSQL_Connector::$traza[] = $query;
         }
         $result = @mssql_query($query, $this->link);
         if ($result == false) {
             $err = mssql_get_last_message();
             if ($interrupt) {
                 $this->agrErr("Error en la consulta: <b>\"" . $query . "\"</b><br>\nMensaje de SQL SERVER: \"<i>" . $err . "</i>\"", $interrupt);
             }
             if ($result != false) {
                 mssql_free_result($result);
             }
             return false;
         }
     } else {
         $this->agrErr("No hay conexión valida o BD seleccionada: " . $query);
     }
     if ($raw) {
         return $result;
     }
     $res = null;
     if ($result != null && !is_bool($result) && mssql_num_rows($result) > 0) {
         $aux = array();
         while ($unreg = mssql_fetch_assoc($result)) {
             $aux[] = $unreg;
         }
         $res = $aux;
     } else {
         if (is_bool($result)) {
             $res = $result;
         }
     }
     return $res;
 }
 /**
  * Returns information about a table or a result set
  *
  * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  * is a table name.
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                 string containing the name of a table.
  *                                 While this also accepts a query result
  *                                 resource identifier, this behavior is
  *                                 deprecated.
  * @param int            $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A DB_Error object on failure.
  *
  * @see DB_common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         if (!@mssql_select_db($this->_db, $this->connection)) {
             return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
         }
         $id = @mssql_query("SELECT * FROM {$result} WHERE 1=0", $this->connection);
         $got_string = true;
     } elseif (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Deprecated.  Here for compatibility only.
          */
         $id = $result;
         $got_string = false;
     }
     if (!is_resource($id)) {
         return $this->mssqlRaiseError(DB_ERROR_NEED_MORE_DATA);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $count = @mssql_num_fields($id);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     for ($i = 0; $i < $count; $i++) {
         if ($got_string) {
             $flags = $this->_mssql_field_flags($result, @mssql_field_name($id, $i));
             if (DB::isError($flags)) {
                 return $flags;
             }
         } else {
             $flags = '';
         }
         $res[$i] = array('table' => $got_string ? $case_func($result) : '', 'name' => $case_func(@mssql_field_name($id, $i)), 'type' => @mssql_field_type($id, $i), 'len' => @mssql_field_length($id, $i), 'flags' => $flags);
         if ($mode & DB_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & DB_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     // free the result only if we were called on a table
     if ($got_string) {
         @mssql_free_result($id);
     }
     return $res;
 }
 /**
  * Executes a SQL statement
  * 
  * @param  string|fStatement $statement  The statement to perform
  * @param  array             $params     The parameters for prepared statements
  * @return void
  */
 private function perform($statement, $params)
 {
     fCore::startErrorCapture();
     $extra = NULL;
     if (is_object($statement)) {
         $result = $statement->execute($params, $extra, $statement != $this->statement);
     } elseif ($this->extension == 'ibm_db2') {
         $result = db2_exec($this->connection, $statement, array('cursor' => DB2_FORWARD_ONLY));
     } elseif ($this->extension == 'mssql') {
         $result = mssql_query($statement, $this->connection);
     } elseif ($this->extension == 'mysql') {
         $result = mysql_unbuffered_query($statement, $this->connection);
     } elseif ($this->extension == 'mysqli') {
         $result = mysqli_query($this->connection, $statement, MYSQLI_USE_RESULT);
     } elseif ($this->extension == 'oci8') {
         $extra = oci_parse($this->connection, $statement);
         $result = oci_execute($extra, $this->inside_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS);
     } elseif ($this->extension == 'pgsql') {
         $result = pg_query($this->connection, $statement);
     } elseif ($this->extension == 'sqlite') {
         $result = sqlite_exec($this->connection, $statement, $extra);
     } elseif ($this->extension == 'sqlsrv') {
         $result = sqlsrv_query($this->connection, $statement);
     } elseif ($this->extension == 'pdo') {
         if ($this->type == 'mssql' && !fCore::checkOS('windows')) {
             $result = $this->connection->query($statement);
             if ($result instanceof PDOStatement) {
                 $result->closeCursor();
             }
         } else {
             $result = $this->connection->exec($statement);
         }
     }
     $this->statement = $statement;
     $this->handleErrors(fCore::stopErrorCapture());
     if ($result === FALSE) {
         $this->checkForError($result, $extra, is_object($statement) ? $statement->getSQL() : $statement);
     } elseif (!is_bool($result) && $result !== NULL) {
         if ($this->extension == 'ibm_db2') {
             db2_free_result($result);
         } elseif ($this->extension == 'mssql') {
             mssql_free_result($result);
         } elseif ($this->extension == 'mysql') {
             mysql_free_result($result);
         } elseif ($this->extension == 'mysqli') {
             mysqli_free_result($result);
         } elseif ($this->extension == 'oci8') {
             oci_free_statement($oci_statement);
         } elseif ($this->extension == 'pgsql') {
             pg_free_result($result);
         } elseif ($this->extension == 'sqlsrv') {
             sqlsrv_free_stmt($result);
         }
     }
 }
Beispiel #30
-1
function checkToken($token)
{
    global $url_login, $url_authenn, $sys_code;
    if (isset($token)) {
        $data = getAuthen($token);
        if (isset($data->BappGetSessionResult->Username)) {
            $_SESSION["user_name"] = sprintf("%08s", $data->BappGetSessionResult->Username);
            $_SESSION["name"] = $data->BappGetSessionResult->FullNameTH;
            $_SESSION['token'] = $token;
            $_SESSION['image_url'] = $data->BappGetSessionResult->ImageUrl;
            // Role
            $conn = ConnectDB();
            $sql = "select ROLE_CODE from DB_DS.DBO.GET_ROLE_BY_PER_SYSID ('" . sprintf("%08s", $_SESSION["user_name"]) . "', '" . $sys_code . "')";
            $query = mssql_query($sql);
            $row = mssql_fetch_array($query, MSSQL_ASSOC);
            $_SESSION["role"] = $row['ROLE_CODE'];
            mssql_free_result($query);
            mssql_close($conn);
            header('Location: /meeting/index.php');
        } else {
            header('Location: ' . $url_login);
        }
    } else {
        header('Location: ' . $url_login);
    }
}