Пример #1
0
function xcopy($mssql, $mysql, $db, $table, $sql)
{
    $start = microtime(true);
    mysqli_select_db($mysql, $db);
    mssql_select_db($db, $mssql);
    $result = mssql_query($sql, $mssql, 20000);
    if ($result === false) {
        die("Error creating sync data\n");
    }
    $s = 0;
    $r = mssql_num_rows($result);
    $name_count = mssql_num_fields($result);
    $name_list = "";
    $update_list = "";
    $value_list = "";
    $sql = "";
    $radix = 0;
    for ($i = 0; $i < $name_count; $i++) {
        $x = strtolower(mssql_field_name($result, $i));
        $name_list .= "{$x},";
        if ($x != "dex_row_id") {
            $update_list .= "{$x} = values({$x}),";
        }
    }
    $name_list = rtrim($name_list, ",");
    $update_list = rtrim($update_list, ",");
    do {
        while ($row = mssql_fetch_row($result)) {
            for ($i = 0; $i < $name_count; $i++) {
                $value_list .= "'" . str_replace("'", "''", trim($row[$i])) . "',";
            }
            $value_list = rtrim($value_list, ",");
            $radix++;
            $sql .= "\n({$value_list}),";
            $value_list = "";
            if ($radix > 2000) {
                $sql = trim($sql, ",");
                $sql = "insert into {$table} ({$name_list}) values {$sql} on duplicate key update {$update_list};";
                $rset = mysqli_query($mysql, $sql);
                if ($rset === false) {
                    die("Error inserting mysql data. \n" . mysqli_error($mysql) . "\n\n{$sql}\n\n");
                }
                $radix = 0;
                $sql = "";
            }
            $s++;
        }
    } while (mssql_fetch_batch($result));
    if ($sql != "") {
        $sql = trim($sql, ",");
        $sql = "insert into {$table} ({$name_list}) values {$sql} on duplicate key update {$update_list};";
        $rset = mysqli_query($mysql, $sql);
        if ($rset === false) {
            die("Error inserting mysql data. \n" . mysqli_error($mysql) . "\n\n{$sql}\n\n");
        }
    }
    $end = microtime(true);
    $total = $end - $start;
    echo "imported {$db}.{$table} [ {$s} ] records in {$total} sec.\n";
}
Пример #2
0
 public function columnCount()
 {
     if ($this->_result) {
         return mssql_num_fields($this->_result);
     }
     return 0;
 }
Пример #3
0
function table_copy($xsql, $table)
{
    global $old_gp;
    global $new_gp;
    $name = "";
    $names = "";
    $feilds = "";
    $sql = "truncate table {$table};";
    $inc = 0;
    $rset = mssql_query($xsql, $old_gp);
    while ($line = mssql_fetch_assoc($rset)) {
        $names = "";
        $feilds = "";
        for ($inc = 0; $inc < mssql_num_fields($rset); $inc++) {
            $name = trim(mssql_field_name($rset, $inc));
            if ($names == "") {
                $names = $name;
            } else {
                $names .= ", {$name}";
            }
            if ($feilds == "") {
                $feilds = "'" . str_replace("'", "''", trim($line[$name])) . "'";
            } else {
                $feilds .= ", '" . str_replace("'", "''", trim($line[$name])) . "'";
            }
        }
        $sql .= "insert into {$table} ({$names}) values ({$feilds});\n";
        echo "{$sql}";
        mssql_query($sql, $new_gp);
        $sql = "";
    }
    //echo $sql;
}
Пример #4
0
 public function get_web_log()
 {
     //select the database
     mssql_select_db($this->dbname, $this->dbcon);
     //SQL Select statement
     $xml = new XMLHandler(XML_DIR . "web_request_spk.xml");
     $sql_from_xml = $xml->getNode("web_log");
     $sqlselect = str_replace("FILTER_BY_PROGRAM", "", $sql_from_xml);
     //Run the SQL query
     $result = mssql_query($sqlselect);
     $numfields = mssql_num_fields($result);
     $string_result = "";
     while ($row = mssql_fetch_row($result)) {
         $string_result .= "<tr>";
         for ($i = 0; $i < $numfields; $i++) {
             if (mssql_field_name($result, $i) == "IP_ADDRESS") {
                 $ip = explode(":", $row[$i]);
                 $string_result .= "<td>" . $ip[0] . "</td>";
                 $string_result .= "<td>" . $ip[1] . "</td>";
             } else {
                 $string_result .= "<td>" . $row[$i] . "</td>";
             }
         }
         $string_result .= "</tr>";
     }
     return $string_result;
 }
Пример #5
0
function select_to_table($query)
{
    $results = mssql_query($query) or die("<li>errorno=" . mysql_errno() . "<li>error=" . mysql_error() . "<li>query=" . $query);
    $number_cols = mssql_num_fields($results);
    //display query
    echo "<b>query: {$query}</b>";
    //layout table header
    echo "<table border = 1>\n";
    echo "<tr align left>\n";
    for ($i = 0; $i < $number_cols; $i++) {
        echo "<th>" . mssql_field_name($results, $i) . "</th>\n";
    }
    echo "</tr>\n";
    //end table header
    //layout table body
    while ($row = mssql_fetch_row($results)) {
        echo "<tr align left>\n";
        for ($i = 0; $i < $number_cols; $i++) {
            echo "<td>";
            if (!isset($row[$i])) {
                echo "NULL";
            } else {
                echo $row[$i];
            }
            echo "</td>\n";
        }
        echo "</tr>\n";
    }
    echo "</table>\n";
}
Пример #6
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function mssqlAdapter($d)
 {
     parent::RecordSetAdapter($d);
     $fieldcount = mssql_num_fields($d);
     // grab the number of fields
     $ob = "";
     $be = $this->isBigEndian;
     $fc = pack('N', $fieldcount);
     if (mssql_num_rows($d) > 0) {
         mssql_data_seek($d, 0);
         while ($line = mssql_fetch_row($d)) {
             // write all of the array elements
             $ob .= "\n" . $fc;
             foreach ($line as $value) {
                 // write all of the array elements
                 if (is_string($value)) {
                     // type as string
                     $os = $this->_directCharsetHandler->transliterate($value);
                     //string flag, string length, and string
                     $len = strlen($os);
                     if ($len < 65536) {
                         $ob .= "" . pack('n', $len) . $os;
                     } else {
                         $ob .= "\f" . pack('N', $len) . $os;
                     }
                 } elseif (is_float($value) || is_int($value)) {
                     // type as double
                     $b = pack('d', $value);
                     // pack the bytes
                     if ($be) {
                         // if we are a big-endian processor
                         $r = strrev($b);
                     } else {
                         // add the bytes to the output
                         $r = $b;
                     }
                     $ob .= "" . $r;
                 } elseif (is_bool($value)) {
                     //type as bool
                     $ob .= "";
                     $ob .= pack('c', $value);
                 } elseif (is_null($value)) {
                     // null
                     $ob .= "";
                 }
             }
         }
     }
     $this->serializedData = $ob;
     for ($i = 0; $i < $fieldcount; $i++) {
         // loop over all of the fields
         $this->columnNames[] = $this->_directCharsetHandler->transliterate(mssql_field_name($d, $i));
     }
     $this->numRows = mssql_num_rows($d);
 }
Пример #7
0
 function _performGetBlobFieldNames($result)
 {
     $blobFields = array();
     for ($i = mssql_num_fields($result) - 1; $i >= 0; $i--) {
         $type = mssql_field_type($result, $i);
         if (strpos($type, "BLOB") !== false) {
             $blobFields[] = mssql_field_name($result, $i);
         }
     }
     return $blobFields;
 }
 /**
  * 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);
 }
Пример #9
0
function funDevuelveArregloRecordsetMS($parERecordset, &$parSArray)
{
    // Obtiene las logitudes del arreglo
    $nrMS = mssql_num_rows($parERecordset);
    $nfMS = mssql_num_fields($parERecordset);
    for ($varI = 0; $varI < $nrMS; $varI++) {
        $results = mssql_fetch_array($parERecordset);
        for ($varJ = 0; $varJ < $nfMS; $varJ++) {
            $varFielName = mssql_field_name($parERecordset, $varJ);
            $parSArray[$varFielName][$varI] = $results[$varFielName];
        }
    }
    // Retorna el numero de registros (filas del arreglo(
    return $nrMS;
}
Пример #10
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function mssqlAdapter($d)
 {
     parent::RecordSetAdapter($d);
     $fieldcount = mssql_num_fields($d);
     // grab the number of fields
     for ($i = 0; $i < $fieldcount; $i++) {
         // loop over all of the fields
         $this->columnNames[] = mssql_field_name($d, $i);
     }
     if (mssql_num_rows($d) > 0) {
         mssql_data_seek($d, 0);
         while ($line = mssql_fetch_row($d)) {
             $this->rows[] = $line;
         }
     }
 }
Пример #11
0
 public function read($sql)
 {
     $data = [];
     $result = mssql_query($sql, $this->gp, 10000);
     if ($result === false) {
         throw new \Exception("Error creating sync data");
     }
     $name_count = mssql_num_fields($result);
     do {
         $x = [];
         while ($row = mssql_fetch_assoc($result)) {
             foreach ($row as $key => $value) {
                 $x[strtolower($key)] = trim($value);
             }
             $data[] = $x;
         }
     } while (mssql_fetch_batch($result));
     return $data;
 }
Пример #12
0
 public function get_unit_rfs()
 {
     //select the database
     mssql_select_db($this->dbname, $this->dbcon);
     //SQL Select statement
     $xml = new XMLHandler(XML_DIR . "web_request_spk.xml");
     $sql_from_xml = $xml->getNode("rfs");
     $sqlselect = str_replace("FILTER_BY_PROGRAM", "", $sql_from_xml);
     //Run the SQL query
     $result = mssql_query($sqlselect);
     $numfields = mssql_num_fields($result);
     $string_result = "";
     while ($row = mssql_fetch_row($result)) {
         $string_result .= "<tr>";
         for ($i = 0; $i < $numfields; $i++) {
             $string_result .= "<td>" . $row[$i] . "</td>";
         }
         $string_result .= "</tr>";
     }
     return $string_result;
 }
Пример #13
0
 public function dashboard_summary()
 {
     //select the database
     mssql_select_db($this->dbname, $this->dbcon);
     //SQL Select statement
     $xml = new XMLHandler(XML_DIR . "web_request_spk.xml");
     $sql_from_xml = $xml->getNode("dashboard_summary");
     $sqlselect = str_replace("FILTER_BY_PROGRAM", "'" . $_SESSION["user-ws"] . "'", $sql_from_xml);
     //Run the SQL query
     $result = mssql_query($sqlselect);
     $numfields = mssql_num_fields($result);
     $jsonString = "{\"dt_objectTable\": {\"dt_fieldsCollection\":[@fieldsCollection@],\"tableName\":\"dashboard_summary\",\"modify_status\":\"ORI\"}}";
     $fieldsCollection = "";
     while ($row = mssql_fetch_row($result)) {
         if ($fieldsCollection != "") {
             $fieldsCollection .= ",";
         }
         $fieldsCollection .= "{\"fieldName\":\"" . $row[0] . "\",\"fieldValue\":\"" . $row[1] . "\"}";
     }
     $jsonString = str_replace("@fieldsCollection@", $fieldsCollection, $jsonString);
     return $jsonString;
 }
 /**
  * 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);
     }
 }
 function sql_num_fields($sqltype, $result)
 {
     if ($sqltype == 'mysql') {
         if (class_exists('mysqli_result')) {
             return $result->field_count;
         } elseif (function_exists('mysql_num_fields')) {
             return mysql_num_fields($result);
         }
     } elseif ($sqltype == 'mssql') {
         if (function_exists('sqlsrv_num_fields')) {
             return sqlsrv_num_fields($result);
         } elseif (function_exists('mssql_num_fields')) {
             return mssql_num_fields($result);
         }
     } elseif ($sqltype == 'pgsql') {
         return pg_num_fields($result);
     } elseif ($sqltype == 'oracle') {
         return oci_num_fields($result);
     } elseif ($sqltype == 'sqlite3') {
         return $result->numColumns();
     } elseif ($sqltype == 'sqlite') {
         return sqlite_num_fields($result);
     } elseif ($sqltype == 'odbc') {
         return odbc_num_fields($result);
     } elseif ($sqltype == 'pdo') {
         return $result->columnCount();
     }
 }
Пример #16
0
 function _initrs()
 {
     global $ADODB_COUNTRECS;
     $this->_numOfRows = $ADODB_COUNTRECS ? @mssql_num_rows($this->_queryID) : -1;
     $this->_numOfFields = @mssql_num_fields($this->_queryID);
 }
 /**	
  * Get number of fields in a result
  * @param Mixed qHanle		The query handle
  * @return Number
  */
 public function num_fields($qHandle)
 {
     return @mssql_num_fields($qHandle);
 }
Пример #18
0
 public function CountFields()
 {
     return mssql_num_fields($this->objMsSqlResult);
 }
Пример #19
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;
 }
Пример #20
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;
 }
Пример #21
0
 /**
  * Returns information about a table or a result set
  *
  * NOTE: doesn't support table name and flags if called from a db_result
  *
  * @param  mixed $resource SQL Server result identifier or table name
  * @param  int $mode A valid tableInfo mode (DB_TABLEINFO_ORDERTABLE or
  *                   DB_TABLEINFO_ORDER)
  *
  * @return array An array with all the information
  */
 function tableInfo($result, $mode = null)
 {
     $count = 0;
     $id = 0;
     $res = array();
     /*
      * depending on $mode, metadata returns the following values:
      *
      * - mode is false (default):
      * $result[]:
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *
      * - mode is DB_TABLEINFO_ORDER
      * $result[]:
      *   ["num_fields"] number of metadata records
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *   ["order"][field name]  index of field named "field name"
      *   The last one is used, if you have a field name, but no index.
      *   Test:  if (isset($result['meta']['myfield'])) { ...
      *
      * - mode is DB_TABLEINFO_ORDERTABLE
      *    the same as above. but additionally
      *   ["ordertable"][table name][field name] index of field
      *      named "field name"
      *
      *      this is, because if you have fields from different
      *      tables with the same field name * they override each
      *      other with DB_TABLEINFO_ORDER
      *
      *      you can combine DB_TABLEINFO_ORDER and
      *      DB_TABLEINFO_ORDERTABLE with DB_TABLEINFO_ORDER |
      *      DB_TABLEINFO_ORDERTABLE * or with DB_TABLEINFO_FULL
      */
     // if $result is a string, then we want information about a
     // table without a resultset
     if (is_string($result)) {
         $id = mssql_query("SELECT * FROM {$result}", $this->connection);
         if (empty($id)) {
             return $this->mssqlRaiseError();
         }
     } else {
         // else we want information about a resultset
         $id = $result;
         if (empty($id)) {
             return $this->mssqlRaiseError();
         }
     }
     $count = @mssql_num_fields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (empty($mode)) {
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = is_string($result) ? $result : '';
             $res[$i]['name'] = @mssql_field_name($id, $i);
             $res[$i]['type'] = @mssql_field_type($id, $i);
             $res[$i]['len'] = @mssql_field_length($id, $i);
             $res[$i]['flags'] = '';
         }
     } else {
         // full
         $res['num_fields'] = $count;
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = is_string($result) ? $result : '';
             $res[$i]['name'] = @mssql_field_name($id, $i);
             $res[$i]['type'] = @mssql_field_type($id, $i);
             $res[$i]['len'] = @mssql_field_length($id, $i);
             $res[$i]['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 (is_string($result)) {
         @mssql_free_result($id);
     }
     return $res;
 }
function db_numfields($lhandle)
{
    return @mssql_num_fields($lhandle);
}
Пример #23
0
 /**
  * Enter description here...
  *
  * @param unknown_type $results
  */
 function resultSet(&$results)
 {
     $this->results =& $results;
     $this->map = array();
     $numFields = mssql_num_fields($results);
     $index = 0;
     $j = 0;
     while ($j < $numFields) {
         $column = mssql_field_name($results, $j);
         if (strpos($column, '__')) {
             if (isset($this->__fieldMappings[$column]) && strpos($this->__fieldMappings[$column], '.')) {
                 $map = explode('.', $this->__fieldMappings[$column]);
             } elseif (isset($this->__fieldMappings[$column])) {
                 $map = array(0, $this->__fieldMappings[$column]);
             } else {
                 $map = array(0, $column);
             }
             $this->map[$index++] = $map;
         } else {
             $this->map[$index++] = array(0, $column);
         }
         $j++;
     }
 }
 function get_result()
 {
     $this->rows = array();
     $this->columns = array();
     $this->num_rows = $this->num_fields = 0;
     switch ($this->db) {
         case 'MySQL':
             $this->num_rows = @mysql_num_rows($this->res);
             $this->num_fields = @mysql_num_fields($this->res);
             while (false !== ($this->rows[] = @mysql_fetch_assoc($this->res))) {
             }
             @mysql_free_result($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
         case 'MSSQL':
             $this->num_rows = @mssql_num_rows($this->res);
             $this->num_fields = @mssql_num_fields($this->res);
             while (false !== ($this->rows[] = @mssql_fetch_assoc($this->res))) {
             }
             @mssql_free_result($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
         case 'PostgreSQL':
             $this->num_rows = @pg_num_rows($this->res);
             $this->num_fields = @pg_num_fields($this->res);
             while (false !== ($this->rows[] = @pg_fetch_assoc($this->res))) {
             }
             @pg_free_result($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
         case 'Oracle':
             $this->num_fields = @ocinumcols($this->res);
             while (false !== ($this->rows[] = @oci_fetch_assoc($this->res))) {
                 $this->num_rows++;
             }
             @ocifreestatement($this->res);
             if ($this->num_rows) {
                 $this->columns = @array_keys($this->rows[0]);
                 return 1;
             }
             break;
     }
     return 0;
 }
Пример #25
0
 /**
  * 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  MDB2_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 MDB2_Error object on failure.
  *
  * @see MDB2_Driver_Common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         return parent::tableInfo($result, $mode);
     }
     $db =& $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
     if (!is_resource($resource)) {
         return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
     }
     if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
         if ($db->options['field_case'] == CASE_LOWER) {
             $case_func = 'strtolower';
         } else {
             $case_func = 'strtoupper';
         }
     } else {
         $case_func = 'strval';
     }
     $count = @mssql_num_fields($resource);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     $db->loadModule('Datatype', null, true);
     for ($i = 0; $i < $count; $i++) {
         $res[$i] = array('table' => '', 'name' => $case_func(@mssql_field_name($resource, $i)), 'type' => @mssql_field_type($resource, $i), 'length' => @mssql_field_length($resource, $i), 'flags' => '');
         $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
         if (PEAR::isError($mdb2type_info)) {
             return $mdb2type_info;
         }
         $res[$i]['mdb2type'] = $mdb2type_info[0][0];
         if ($mode & MDB2_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     return $res;
 }
Пример #26
0
 /**
  * Count the number of columns returned by the DBMS in a query result.
  *
  * @return mixed integer value with the number of columns, a MDB2 error
  *      on failure
  * @access public
  */
 function numCols()
 {
     $cols = @mssql_num_fields($this->result);
     if (is_null($cols)) {
         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 count($this->types);
         }
         return $this->db->raiseError(null, null, null, 'Could not get column count', __FUNCTION__);
     }
     return $cols;
 }
Пример #27
0
 /**
  * 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;
 }
Пример #28
0
 function write_data_mssql($table_name)
 {
     global $db;
     $ary_type = $ary_name = array();
     $ident_set = false;
     $sql_data = '';
     // Grab all of the data from current table.
     $sql = "SELECT *\n\t\t\tFROM {$table_name}";
     $result = $db->sql_query($sql);
     $retrieved_data = mssql_num_rows($result);
     $i_num_fields = mssql_num_fields($result);
     for ($i = 0; $i < $i_num_fields; $i++) {
         $ary_type[$i] = mssql_field_type($result, $i);
         $ary_name[$i] = mssql_field_name($result, $i);
     }
     if ($retrieved_data) {
         $sql = "SELECT 1 as has_identity\n\t\t\t\tFROM INFORMATION_SCHEMA.COLUMNS\n\t\t\t\tWHERE COLUMNPROPERTY(object_id('{$table_name}'), COLUMN_NAME, 'IsIdentity') = 1";
         $result2 = $db->sql_query($sql);
         $row2 = $db->sql_fetchrow($result2);
         if (!empty($row2['has_identity'])) {
             $sql_data .= "\nSET IDENTITY_INSERT {$table_name} ON\nGO\n";
             $ident_set = true;
         }
         $db->sql_freeresult($result2);
     }
     while ($row = $db->sql_fetchrow($result)) {
         $schema_vals = $schema_fields = array();
         // Build the SQL statement to recreate the data.
         for ($i = 0; $i < $i_num_fields; $i++) {
             $str_val = $row[$ary_name[$i]];
             if (preg_match('#char|text|bool|varbinary#i', $ary_type[$i])) {
                 $str_quote = '';
                 $str_empty = "''";
                 $str_val = sanitize_data_mssql(str_replace("'", "''", $str_val));
             } else {
                 if (preg_match('#date|timestamp#i', $ary_type[$i])) {
                     if (empty($str_val)) {
                         $str_quote = '';
                     } else {
                         $str_quote = "'";
                     }
                 } else {
                     $str_quote = '';
                     $str_empty = 'NULL';
                 }
             }
             if (empty($str_val) && $str_val !== '0' && !(is_int($str_val) || is_float($str_val))) {
                 $str_val = $str_empty;
             }
             $schema_vals[$i] = $str_quote . $str_val . $str_quote;
             $schema_fields[$i] = $ary_name[$i];
         }
         // Take the ordered fields and their associated data and build it
         // into a valid sql statement to recreate that field in the data.
         $sql_data .= "INSERT INTO {$table_name} (" . implode(', ', $schema_fields) . ') VALUES (' . implode(', ', $schema_vals) . ");\nGO\n";
         $this->flush($sql_data);
         $sql_data = '';
     }
     $db->sql_freeresult($result);
     if ($retrieved_data && $ident_set) {
         $sql_data .= "\nSET IDENTITY_INSERT {$table_name} OFF\nGO\n";
     }
     $this->flush($sql_data);
 }
Пример #29
0
 /**
  * Number of fields in the result set
  *
  * @return	int
  */
 public function num_fields()
 {
     return mssql_num_fields($this->result_id);
 }
function querY($type, $host, $user, $pass, $db = '', $query)
{
    $res = '';
    switch ($type) {
        case 'MySQL':
            if (!function_exists('mysql_connect')) {
                return 0;
            }
            $link = mysql_connect($host, $user, $pass);
            if ($link) {
                if (!empty($db)) {
                    mysql_select_db($db, $link);
                }
                $result = mysql_query($query, $link);
                while ($data = mysql_fetch_row($result)) {
                    $res .= implode('|-|-|-|-|-|', $data) . '|+|+|+|+|+|';
                }
                $res .= '[+][+][+]';
                for ($i = 0; $i < mysql_num_fields($result); $i++) {
                    $res .= mysql_field_name($result, $i) . '[-][-][-]';
                }
                mysql_close($link);
                return $res;
            }
            break;
        case 'MSSQL':
            if (!function_exists('mssql_connect')) {
                return 0;
            }
            $link = mssql_connect($host, $user, $pass);
            if ($link) {
                if (!empty($db)) {
                    mssql_select_db($db, $link);
                }
                $result = mssql_query($query, $link);
                while ($data = mssql_fetch_row($result)) {
                    $res .= implode('|-|-|-|-|-|', $data) . '|+|+|+|+|+|';
                }
                $res .= '[+][+][+]';
                for ($i = 0; $i < mssql_num_fields($result); $i++) {
                    $res .= mssql_field_name($result, $i) . '[-][-][-]';
                }
                mssql_close($link);
                return $res;
            }
            break;
        case 'Oracle':
            if (!function_exists('ocilogon')) {
                return 0;
            }
            $link = ocilogon($user, $pass, $db);
            if ($link) {
                $stm = ociparse($link, $query);
                ociexecute($stm, OCI_DEFAULT);
                while ($data = ocifetchinto($stm, $data, OCI_ASSOC + OCI_RETURN_NULLS)) {
                    $res .= implode('|-|-|-|-|-|', $data) . '|+|+|+|+|+|';
                }
                $res .= '[+][+][+]';
                for ($i = 0; $i < oci_num_fields($stm); $i++) {
                    $res .= oci_field_name($stm, $i) . '[-][-][-]';
                }
                return $res;
            }
            break;
        case 'PostgreSQL':
            if (!function_exists('pg_connect')) {
                return 0;
            }
            $link = pg_connect("host={$host} dbname={$db} user={$user} password={$pass}");
            if ($link) {
                $result = pg_query($link, $query);
                while ($data = pg_fetch_row($result)) {
                    $res .= implode('|-|-|-|-|-|', $data) . '|+|+|+|+|+|';
                }
                $res .= '[+][+][+]';
                for ($i = 0; $i < pg_num_fields($result); $i++) {
                    $res .= pg_field_name($result, $i) . '[-][-][-]';
                }
                pg_close($link);
                return $res;
            }
            break;
    }
    return 0;
}