function GetFields()
 {
     $_fields = array();
     $_result = mssql_query($this->SelectCommand, $this->_Link);
     while ($_prop = mssql_fetch_field($_result)) {
         $_field = array("Name" => $_prop->name, "Type" => $_prop->type, "Not_Null" => 0);
         array_push($_fields, $_field);
     }
     return $_fields;
 }
 /**
  * Constructor
  *
  * @param   resource handle
  */
 public function __construct($result, TimeZone $tz = NULL)
 {
     $fields = array();
     if (is_resource($result)) {
         for ($i = 0, $num = mssql_num_fields($result); $i < $num; $i++) {
             $field = mssql_fetch_field($result, $i);
             $fields[$field->name] = $field->type;
         }
     }
     parent::__construct($result, $fields, $tz);
 }
예제 #3
0
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access	public
  * @return	array
  */
 function field_data()
 {
     $retval = array();
     while ($field = mssql_fetch_field($this->result_id)) {
         $F = new stdClass();
         $F->name = $field->name;
         $F->type = $field->type;
         $F->max_length = $field->max_length;
         $F->primary_key = 0;
         $F->default = '';
         $retval[] = $F;
     }
     return $retval;
 }
 /**
  * Dynamic Get Function Override
  *
  * @param $name
  *   A string containing the name of the property to get.
  * @return
  *   Value of the property.
  */
 public function __get($propertyName)
 {
     //        global $firePHP;
     if ($propertyName == 'columns') {
         if (!isset($this->_columns)) {
             //---- Get Columns
             $this->_columns = new anvilCollection();
             $i = 0;
             //                $sql = 'SHOW COLUMNS FROM ';
             while ($i < mssql_num_fields($this->result)) {
                 $meta = mssql_fetch_field($this->result, $i);
                 if ($meta) {
                     //                       $firePHP->_log($meta);
                     $newColumn = new anvilData_mssql_Column($meta->name, $meta->type);
                     $this->_columns->add($newColumn);
                 }
                 $i++;
             }
         }
         return $this->_columns;
     } else {
         return parent::__get($propertyName);
     }
 }
예제 #5
0
파일: Mssql.php 프로젝트: kjgarza/ushahidi
 public function list_fields()
 {
     $field_names = array();
     while ($field = mssql_fetch_field($this->result)) {
         $field_names[] = $field->name;
     }
     return $field_names;
 }
예제 #6
0
파일: mssql.php 프로젝트: vlki/dibi
 /**
  * Returns metadata for all columns in a result set.
  * @return array
  */
 public function getColumnsMeta()
 {
     $count = mssql_num_fields($this->resultSet);
     $res = array();
     for ($i = 0; $i < $count; $i++) {
         $row = (array) mssql_fetch_field($this->resultSet, $i);
         $res[] = array('name' => $row['name'], 'fullname' => $row['column_source'] ? $row['column_source'] . '.' . $row['name'] : $row['name'], 'table' => $row['column_source'], 'nativetype' => $row['type']);
     }
     return $res;
 }
예제 #7
0
 /**
  * mysql_fetch_field() wrapper
  * Returns false if the field doesn't exist
  *
  * @param $table
  * @param $field
  */
 function fieldInfo($table, $field)
 {
     $table = $this->tableName($table);
     $res = $this->query("SELECT TOP 1 * FROM {$table}");
     $n = mssql_num_fields($res->result);
     for ($i = 0; $i < $n; $i++) {
         $meta = mssql_fetch_field($res->result, $i);
         if ($field == $meta->name) {
             return new MSSQLField($meta);
         }
     }
     return false;
 }
예제 #8
0
function mssql_to_table($sql)
{
    $fields_array = array();
    $num_fields = 0;
    $num_row = 0;
    // find position of "FROM" in query
    $fpos = strpos($sql, 'from');
    // get string starting from the first word after "FROM"
    $strfrom = substr($sql, $fpos + 5, 50);
    // Find position of the first space after the first word in the string
    $Opos = strpos($strfrom, ' ');
    //Get table name. If query pull data from more then one table only first table name will be read.
    $table = substr($strfrom, 0, $Opos);
    // Get result from query
    $result = mssql_query($sql) or die('Invalid query: ' . mssql_error());
    $num_row = mssql_numrows($result);
    print '<html>';
    print '<head><title>';
    print 'View&nbsp' . $table . '</title>';
    print '<link rel="stylesheet" href="style.css">';
    print "</head>";
    print '<body><br>';
    if ($num_row > 0) {
        //Get number of fields in query
        $num_fields = mssql_num_fields($result);
        # get column metadata
        $i = 0;
        //Set table width 15% for each column
        $width = 15 * $num_fields;
        print '<br><table width=' . $width . '% align="center"><tr>';
        print '<tr><th colspan=' . $num_fields . '>View&nbsp;' . $table . '</th></tr>';
        while ($i < $num_fields) {
            //Get fields (columns) names
            $meta = mssql_fetch_field($result);
            $fields_array[] = $meta->name;
            //Display column headers in upper case
            print '<th><b>' . strtoupper($fields_array[$i]) . '</b></th>';
            $i = $i + 1;
        }
        print '</tr>';
        //Get values for each row and column
        while ($row = mssql_fetch_row($result)) {
            print '<tr>';
            for ($i = 0; $i < $num_fields; $i++) {
                //Display values for each row and column
                print '<td>' . $row[$i] . '</td>';
            }
            print '</tr>';
        }
    }
    return;
}
예제 #9
0
 /**
  * Get column information
  * @param  int
  * @return object
  */
 protected function fetch_field($intOffset)
 {
     return @mssql_fetch_field($this->resResult, $intOffset);
 }
예제 #10
0
 function FetchField($fieldOffset = -1)
 {
     if ($fieldOffset != -1) {
         $f = @mssql_fetch_field($this->_queryID, $fieldOffset);
     } else {
         if ($fieldOffset == -1) {
             /*	The $fieldOffset argument is not provided thus its -1 	*/
             $f = @mssql_fetch_field($this->_queryID);
         }
     }
     $false = false;
     if (empty($f)) {
         return $false;
     }
     return $f;
 }
예제 #11
0
 function metadata($table)
 {
     $count = 0;
     $id = 0;
     $res = array();
     $this->connect();
     $id = mssql_query("select * from {$table}", $this->Link_ID);
     if (!$id) {
         $this->halt('Metadata query failed.');
     }
     $count = mssql_num_fields($id);
     for ($i = 0; $i < $count; $i++) {
         $info = mssql_fetch_field($id, $i);
         $res[$info->name] = $info;
         /*
         				$res[$i]['table'] = $table;
         				$res[$i]['name']  = $info->name;
         				$res[$i]['len']   = $info->max_length;
         				$res[$i]['flags'] = $info->numeric;
         				$res[$i]['type'] = $info->type;
         */
     }
     $this->free_result();
     return $res;
 }
예제 #12
0
 function GetColumnNames($result, &$column_names)
 {
     $result_value = intval($result);
     if (!isset($this->highest_fetched_row[$result_value])) {
         return $this->SetError("Get column names", "it was specified an inexisting result set");
     }
     if (!isset($this->columns[$result_value])) {
         $this->columns[$result_value] = array();
         for ($column = 0; @mssql_field_seek($result, $column); $column++) {
             $field = mssql_fetch_field($result);
             $this->columns[$result_value][strtolower($field->name)] = $column;
         }
     }
     $column_names = $this->columns[$result_value];
     return 1;
 }
예제 #13
0
 /**
  * @see DBManager::getFieldsArray()
  */
 public function getFieldsArray($result, $make_lower_case = false)
 {
     $field_array = array();
     if (!isset($result) || empty($result)) {
         return 0;
     }
     $i = 0;
     while ($i < mssql_num_fields($result)) {
         $meta = mssql_fetch_field($result, $i);
         if (!$meta) {
             return 0;
         }
         if ($make_lower_case == true) {
             $meta->name = strtolower($meta->name);
         }
         $field_array[] = $meta->name;
         $i++;
     }
     return $field_array;
 }
예제 #14
0
 public function columnData()
 {
     if (empty($this->query)) {
         return false;
     }
     $columns = array();
     for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) {
         $field = mssql_fetch_field($this->query, $i);
         $columns[$i] = new stdClass();
         $columns[$i]->name = $field->name;
         $columns[$i]->type = $field->type;
         $columns[$i]->maxLength = $field->max_length;
         $columns[$i]->primaryKey = false;
     }
     return $columns;
 }
예제 #15
0
 function fetch_fields($query)
 {
     return mssql_fetch_field($query);
 }
예제 #16
0
 /**
  * Get field information
  * 
  * @param	resource	$statement - The result resource that is being evaluated.
  * @param	integer		$field_offset - The numerical field offset. If the field offset is not specified, the next field that was not yet retrieved by this function is retrieved. The field_offset starts at 0.
  * @return	object
  */
 public function fetchField($statement, $field_offset = -1)
 {
     if (!is_resource($statement)) {
         throw new LikePDOException("There is no active statement");
         return false;
     } else {
         return mssql_fetch_field($statement, $field_offset);
     }
 }
예제 #17
0
 function currentid($seq_name)
 {
     $this->connect();
     $currentid = 0;
     $q = sprintf("select nextid from %s where seq_name = '%s'", $this->Seq_Table, $seq_name);
     $id = @mssql_query($q, $this->Link_ID);
     if ($res = mssql_fetch_row($id)) {
         // add to res[<key>]
         $count = mssql_num_fields($id);
         for ($i = 0; $i < $count; $i++) {
             $fieldinfo = mssql_fetch_field($id, $i);
             $res[strtolower($fieldinfo->name)] = $res[$i];
         }
     }
     if (is_array($res)) {
         $currentid = $res["nextid"];
     }
     return $currentid;
 }
예제 #18
0
 protected function _table_name($field)
 {
     return mssql_fetch_field($this->_result, $field)->column_source;
 }
<?php

include '../header.php';
$db = new Conexion();
$link = Conectarse();
$Ot = $_POST['ot'];
$Horainicio = $_POST['horainicio'];
$Horafin = $_POST['horafin'];
$date = new DateTime($_POST['fecha']);
$Fecha = $date->format('Y-m-d');
$HorasTrabajo = $Horafin - $horainicio;
$Horashombre = (floatval($Horafin) - floatval($Horainicio)) / 60;
/*1. Obtener el centro de costo de la ot*/
$sql = "SELECT  CODIGOCENTROCOSTO,CODIGOOT\n\tFROM [020BDCOMUN].DBO.CENCOSOT  WHERE\n\tCODIGOOT IN (SELECT OF_COD FROM [011BDCOMUN].DBO.ORD_FAB\n WHERE OF_ESTADO='ACTIVO') AND CODIGOOT='{$Ot}'";
$result = mssql_query($sql, $link);
if ($row = mssql_fetch_array($result)) {
    mssql_field_seek($result, 0);
    while ($field = mssql_fetch_field($result)) {
    }
    do {
        $Cencos = $row['CODIGOCENTROCOSTO'];
    } while ($row = mssql_fetch_array($result));
} else {
    echo "error";
}
$reporte = new Reporte($_POST['id'], $Fecha, $DescHorainicio, $DescHorafin, $HorasTrabajo, $_POST['detalle'], $Horashombre, $Ot, $Cencos, $_SESSION['id'], $_POST['proceso'], $_POST['clasificacion']);
$reporte->Actualizar();
예제 #20
0
 /**
  * Returns metadata for all columns in a result set.
  *
  * @return array
  */
 public function getColumnsMeta()
 {
     $count = mssql_num_fields($this->resultSet);
     $meta = array();
     for ($i = 0; $i < $count; $i++) {
         // items 'name' and 'table' are required
         $info = (array) mssql_fetch_field($this->resultSet, $i);
         $info['table'] = $info['column_source'];
         $meta[] = $info;
     }
     return $meta;
 }
예제 #21
0
    public function get_html($command, $display_field_headers = true, $table_attribs = 'border="0" cellpadding="3" cellspacing="2" style="padding-bottom:5px; border:1px solid #cccccc; font-size:13px; font-family:verdana;"')
    {
        if (!$command) {
            exit("No Query Command Specified !!");
        }
        $this->query = $command;
        $this->result = mssql_query($command) or $this->setError(mssql_error(), mssql_errno());
        if ($this->result) {
            $this->rows = intval(mssql_num_rows($this->result));
            $num_fields = mssql_num_fields($this->result);
            print '<br /><br /><div>
						<table ' . $table_attribs . '>' . "\n" . '<tr>';
            if ($display_field_headers == true) {
                // printing table headers
                for ($i = 0; $i < $num_fields; $i++) {
                    $field = mssql_fetch_field($this->result);
                    print "<td bgcolor='#f6f6f6' style=' border:1px solid #cccccc;'><strong style='color:#666666;'>" . ucwords($field->name) . "</strong></td>\n";
                }
                print "</tr>\n";
            }
            // printing table rows
            while ($row = mssql_fetch_row($this->result)) {
                print "<tr>";
                foreach ($row as $td) {
                    print "<td bgcolor='#f6f6f6'>{$td}</td>\n";
                }
                print "</tr>\n";
            }
            print "</table></div><br /><br />";
        }
    }
예제 #22
0
function sti_mssql_get_data($connection_string, $data_source_name, $query)
{
    $link = sti_mssql_connect($connection_string);
    $result = sti_mssql_query($query, $link);
    $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Database>";
    $columns = array();
    if (function_exists("mssql_fetch_field")) {
        while ($column = mssql_fetch_field($result)) {
            array_push($columns, $column);
        }
    } else {
        foreach (sqlsrv_field_metadata($result) as $field_metadata) {
            array_push($columns, $field_metadata);
        }
    }
    if (function_exists("mssql_fetch_assoc")) {
        while ($row = mssql_fetch_assoc($result)) {
            $xml_output .= "<{$data_source_name}>";
            foreach ($columns as $column) {
                $value = $row[$column->name];
                $column_type = sti_mssql_get_column_type($column->type);
                if ($column_type == "base64Binary") {
                    $value = base64_encode($value);
                } else {
                    if (ord($value[0]) == 0) {
                        $value = sti_bytes_to_int($value);
                    } else {
                        $value = str_replace("&", "&amp;", $value);
                        $value = str_replace("<", "&lt;", $value);
                        $value = str_replace(">", "&gt;", $value);
                    }
                }
                $columnName = encodeName($column->name);
                $xml_output .= "<{$columnName}>{$value}</{$columnName}>";
            }
            $xml_output .= "</{$data_source_name}>";
        }
    } else {
        while ($row = sqlsrv_fetch_array($result)) {
            $xml_output .= "<{$data_source_name}>";
            foreach ($columns as $column) {
                $value = $row[$column["Name"]];
                $column_type = sti_mssql_get_column_type($field_metadata["Type"]);
                if ($column_type == "base64Binary") {
                    $value = base64_encode($value);
                } else {
                    if (ord($value[0]) == 0) {
                        $value = sti_bytes_to_int($value);
                    } else {
                        $value = str_replace("&", "&amp;", $value);
                        $value = str_replace("<", "&lt;", $value);
                        $value = str_replace(">", "&gt;", $value);
                    }
                }
                $columnName = encodeName($column["Name"]);
                $xml_output .= "<{$columnName}>{$value}</{$columnName}>";
            }
            $xml_output .= "</{$data_source_name}>";
        }
    }
    $xml_output .= "</Database>";
    mssql_free_result($result);
    mssql_close($link);
    return $xml_output;
}
예제 #23
0
 function _post_query($query, $dbh)
 {
     ++$this->num_queries;
     // If there is an error then take note of it..
     if ($this->result == FALSE && ($this->last_error = mssql_get_last_message())) {
         $this->log_query($this->last_error);
         //var_dump($query);
         //var_dump($this->translation_changes);
         $this->print_error();
         return false;
     }
     if (defined('SAVEQUERIES') && SAVEQUERIES) {
         $this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
     }
     if (preg_match("/^\\s*(insert|delete|update|replace) /i", $query)) {
         $this->rows_affected = mssql_rows_affected($dbh);
         // Take note of the insert_id
         if (preg_match("/^\\s*(insert|replace) /i", $query)) {
             $result = @mssql_fetch_object(@mssql_query("SELECT SCOPE_IDENTITY() AS ID"));
             $this->insert_id = $result->ID;
         }
         $return_val = $this->rows_affected;
     } else {
         $i = 0;
         while ($i < @mssql_num_fields($this->result)) {
             $field = @mssql_fetch_field($this->result, $i);
             $new_field = new stdClass();
             $new_field->name = $field->name;
             $new_field->table = $field->column_source;
             $new_field->def = null;
             $new_field->max_length = $field->max_length;
             $new_field->not_null = true;
             $new_field->primary_key = null;
             $new_field->unique_key = null;
             $new_field->multiple_key = null;
             $new_field->numeric = $field->numeric;
             $new_field->blob = null;
             $new_field->type = $field->type;
             if (isset($field->unsigned)) {
                 $new_field->unsigned = $field->unsigned;
             } else {
                 $new_field->unsigned = null;
             }
             $new_field->zerofill = null;
             $this->col_info[$i] = $new_field;
             $i++;
         }
         $num_rows = 0;
         while ($row = @mssql_fetch_object($this->result)) {
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         $this->last_result = $this->fix_results($this->last_result);
         // perform limit
         if (!empty($this->limit)) {
             $this->last_result = array_slice($this->last_result, $this->limit['from'], $this->limit['to']);
             $num_rows = count($this->last_result);
         }
         @mssql_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     $this->log_query();
     return $return_val;
 }
 public function fetchAll($fetch_style)
 {
     switch ($fetch_style) {
         case self::FETCH_ARRAY:
             $results = array();
             while ($result = mssql_fetch_array($this->resource)) {
                 $results[] = $result;
             }
             break;
         case self::FETCH_ASSOC:
             $results = array();
             while ($result = mssql_fetch_assoc($this->resource)) {
                 $results[] = $result;
             }
             break;
         case self::FETCH_BATCH:
             $results = array();
             while ($result = mssql_fetch_batch($this->resource)) {
                 $results[] = $result;
             }
             break;
         case self::FETCH_FIELD:
             $results = array();
             while ($result = mssql_fetch_field($this->resource)) {
                 $results[] = $result;
             }
             break;
         case self::FETCH_OBJ:
             $results = array();
             while ($result = mssql_fetch_object($this->resource)) {
                 $results[] = $result;
             }
             break;
         case self::FETCH_ROW:
             $results = array();
             while ($result = mssql_fetch_row($this->resource)) {
                 $results[] = $result;
             }
             break;
     }
     return $results;
 }
예제 #25
0
 public function FetchField()
 {
     if ($objField = mssql_fetch_field($this->objMsSqlResult)) {
         return new QSqlServerDatabaseField($objField, $this->objDb);
     }
 }
예제 #26
0
 function query($query)
 {
     //if flag to convert query from MySql syntax to MS-Sql syntax is true
     //convert the query
     if ($this->convertMySqlToMSSqlQuery == true) {
         $query = $this->ConvertMySqlToMSSql($query);
     }
     // Initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // For reg expressions
     $query = trim($query);
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Count how many queries there have been
     $this->num_queries++;
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         return $cache;
     }
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbhost);
         $this->select($this->dbname);
     }
     // Perform the query via std mssql_query function..
     $this->result = @mssql_query($query);
     // If there is an error then take note of it..
     if ($this->result == false) {
         $get_errorcodeSql = "SELECT @@ERROR as errorcode";
         $error_res = @mssql_query($get_errorcodeSql, $this->dbh);
         $errorCode = @mssql_result($error_res, 0, "errorcode");
         $get_errorMessageSql = "SELECT severity as errorSeverity, text as errorText FROM sys.messages  WHERE message_id = " . $errorCode;
         $errormessage_res = @mssql_query($get_errorMessageSql, $this->dbh);
         if ($errormessage_res) {
             $errorMessage_Row = @mssql_fetch_row($errormessage_res);
             $errorSeverity = $errorMessage_Row[0];
             $errorMessage = $errorMessage_Row[1];
         }
         $sqlError = "ErrorCode: " . $errorCode . " ### Error Severity: " . $errorSeverity . " ### Error Message: " . $errorMessage . " ### Query: " . $query;
         $is_insert = true;
         $this->register_error($sqlError);
         $this->show_errors ? trigger_error($sqlError, E_USER_WARNING) : null;
         return false;
     }
     // Query was an insert, delete, update, replace
     $is_insert = false;
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @mssql_rows_affected($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $identityresultset = @mssql_query("select SCOPE_IDENTITY()");
             if ($identityresultset != false) {
                 $identityrow = @mssql_fetch_row($identityresultset);
                 $this->insert_id = $identityrow[0];
             }
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         while ($i < @mssql_num_fields($this->result)) {
             $this->col_info[$i] = @mssql_fetch_field($this->result);
             $i++;
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @mssql_fetch_object($this->result)) {
             // Store relults as an objects within main array
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @mssql_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_val;
 }
예제 #27
0
 function FetchField($fieldOffset = -1)
 {
     if ($fieldOffset != -1) {
         return @mssql_fetch_field($this->_queryID, $fieldOffset);
     } else {
         if ($fieldOffset == -1) {
             /*	The $fieldOffset argument is not provided thus its -1 	*/
             return @mssql_fetch_field($this->_queryID);
         }
     }
     return null;
 }
예제 #28
0
파일: db_mssql.php 프로젝트: brustj/tracmor
 function db_columnType($oStmt, $iPos)
 {
     $oFields = mssql_fetch_field($oStmt, $iPos - 1);
     return $oFields->type;
 }
예제 #29
0
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @return	array
  */
 public function field_data()
 {
     $retval = array();
     for ($i = 0, $c = $this->num_field(); $i < $c; $i++) {
         $field = mssql_fetch_field($this->result_id, $i);
         $retval[$i] = new stdClass();
         $retval[$i]->name = $field->name;
         $retval[$i]->type = $field->type;
         $retval[$i]->max_length = $field->max_length;
     }
     return $retval;
 }
예제 #30
0
파일: db.php 프로젝트: joshreisner/hcfa-cc
function db_fetch_field($result, $i)
{
    global $_josh;
    db_open();
    if ($_josh["db"]["language"] == "mysql") {
        return mysql_fetch_field($result, $i);
    } elseif ($_josh["db"]["language"] == "mssql") {
        return mssql_fetch_field($result, $i);
    }
}