Example #1
4
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * The body of this method was provided by Mario Falomir... Thanks.
  * 
  * @param resource $d The datasource resource
  */
 function odbcAdapter($d)
 {
     parent::RecordSetAdapter($d);
     // count number of fields
     $fieldcount = odbc_num_fields($d);
     $ob = "";
     $be = $this->isBigEndian;
     $fc = pack('N', $fieldcount);
     if (odbc_num_rows($d) > 0) {
         $line = odbc_fetch_row($d, 0);
         do {
             // write all of the array elements
             $ob .= "\n" . $fc;
             for ($i = 1; $i <= $fieldcount; $i++) {
                 // write all of the array elements
                 $value = odbc_result($d, $i);
                 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 .= "";
                 }
             }
         } while ($line = odbc_fetch_row($d));
     }
     $this->serializedData = $ob;
     // grab the number of fields
     // loop over all of the fields
     for ($i = 1; $i <= $fieldcount; $i++) {
         // decode each field name ready for encoding when it goes through serialization
         // and save each field name into the array
         $this->columnNames[$i - 1] = $this->_directCharsetHandler->transliterate(odbc_field_name($d, $i));
     }
     $this->numRows = odbc_num_rows($d);
 }
 function num_fields($res)
 {
     if ($num = odbc_num_fields($res)) {
         return $num;
     } else {
         return false;
     }
 }
Example #3
0
 public function fetchFields()
 {
     $fields = array();
     for ($i = 0; $i < odbc_num_fields($this->result); ++$i) {
         $fields[] = odbc_field_name($this->result, $i);
     }
     return $fields;
 }
Example #4
0
function DBGetQuery($result)
{
    // Devuelve la siguiente fila dentro del result-array..
    $arr = array();
    if (odbc_fetch_row($result)) {
        for ($i = 1; $i <= odbc_num_fields($result); $i++) {
            $value = odbc_result($result, $i);
            array_push($arr, $value);
        }
    }
    return $arr;
}
Example #5
0
function listeFourni()
{
    global $cnx, $liste;
    $cnx = ouvresylob(1);
    //on selectionne tous les champs qui seront utiles
    $sQuery = "SELECT distinct (f.no_frn) as id, f.rais_soc as raison_sociale, a.nom as contact, f.telph as tel, telex as email, \r\n                        CONCAT(a.adr1,a.adr2) as adresse, CONCAT(a.cd_post,a.ville) as ville\r\n                FROM (informix.bas_frn f \r\n                INNER JOIN informix.bas_adrfrn a ON a.no_frn = f.no_frn) \r\n                LEFT JOIN informix.zz_materiel m ON m.frn_materiel = f.no_frn\r\n                WHERE f.no_frn is not null\r\n                AND a.no_adr = 1\r\n                ORDER BY f.rais_soc asc, a.nom asc";
    //echo $sQuery;
    $res = odbc_exec($cnx, $sQuery);
    $i = 0;
    while (odbc_fetch_row($res)) {
        for ($j = 1; $j <= odbc_num_fields($res); $j++) {
            $liste[$i][odbc_field_name($res, $j)] = odbc_result($res, $j);
        }
        $i++;
    }
    //odbc_close($cnx);
    return $liste;
}
Example #6
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * The body of this method was provided by Mario Falomir... Thanks.
  * 
  * @param resource $d The datasource resource
  */
 function odbcAdapter($d)
 {
     parent::RecordSetAdapter($d);
     // count number of fields
     $fieldcount = odbc_num_fields($d);
     // grab the number of fields
     // loop over all of the fields
     for ($i = 0; $i < $fieldcount; $i++) {
         // decode each field name ready for encoding when it goes through serialization
         // and save each field name into the array
         $this->columns[] = odbc_field_name($d, $i + 1);
     }
     if (odbc_num_rows($d) > 0) {
         $line = odbc_fetch_row($d, 0);
         do {
             $this->rows[] = $line;
         } while ($line = odbc_fetch_row($d));
     }
 }
Example #7
0
 function db_colnum($oStmt)
 {
     return odbc_num_fields($oStmt);
 }
Example #8
0
 function RetrieveODBCData($action)
 {
     $availableActions = array('-delete', '-edit', '-find', '-findall', '-new', '-sqlquery');
     if (!in_array(strtolower($action), $availableActions)) {
         // first off, toss out any requests for actions NOT supported under ODBC
         return new FX_Error("The action requested ({$action}) is not supported under ODBC via FX.php.");
     }
     $odbc_res = odbc_connect($this->database, $this->DBUser, $this->DBPassword);
     // although username and password are optional for this function, FX.php expects them to be set
     if ($odbc_res == false) {
         return new FX_Error('Unable to connect to ODBC data source.');
     }
     switch ($action) {
         case '-delete':
         case '-edit':
         case '-find':
         case '-findall':
         case '-new':
             $this->dataQuery = $this->BuildSQLQuery($action);
             if (FX::isError($this->dataQuery)) {
                 return $this->dataQuery;
             }
         case '-sqlquery':
             // note that there is no preceding break, as we don't want to build a query
             $odbc_result = odbc_exec($odbc_res, $this->dataQuery);
             if (!$odbc_result) {
                 $tempErrorText = odbc_errormsg($odbc_res);
                 odbc_close($odbc_res);
                 return new FX_Error("Unsuccessful query: {$this->dataQuery} ({$tempErrorText})");
             }
             $this->foundCount = odbc_num_rows($odbc_result);
             $fieldCount = odbc_num_fields($odbc_result);
             if ($theResult < 0) {
                 $tempErrorText = odbc_errormsg($odbc_res);
                 odbc_close($odbc_res);
                 return new FX_Error("Unable to access field count for current ODBC query.  ({$tempErrorText})");
             }
             $odbc_columns = odbc_columns($odbc_res);
             if (!$odbc_columns) {
                 $tempErrorText = odbc_errormsg($odbc_res);
                 odbc_close($odbc_res);
                 return new FX_Error("Unable to retrieve column data via ODBC.  ({$tempErrorText})");
             }
             while (odbc_fetch_row($odbc_columns)) {
                 $fieldNumber = odbc_result($odbc_columns, 'ORDINAL_POSITION');
                 $this->fieldInfo[$fieldNumber]['name'] = odbc_result($odbc_columns, 'COLUMN_NAME');
                 $this->fieldInfo[$fieldNumber]['type'] = odbc_result($odbc_columns, 'TYPE_NAME');
                 $this->fieldInfo[$fieldNumber]['emptyok'] = odbc_result($odbc_columns, 'IS_NULLABLE');
                 $this->fieldInfo[$fieldNumber]['maxrepeat'] = 1;
                 $this->fieldInfo[$fieldNumber]['extra'] = 'COLUMN_SIZE:' . odbc_result($odbc_columns, 'COLUMN_SIZE') . '|BUFFER_LENGTH:' . odbc_result($odbc_columns, 'BUFFER_LENGTH') . '|NUM_PREC_RADIX:' . odbc_result($odbc_columns, 'NUM_PREC_RADIX');
             }
             while (odbc_fetch_row($odbc_result)) {
                 $tempRow = array();
                 for ($i = 1; $i <= $fieldCount; ++$i) {
                     $theResult = odbc_result($odbc_result, $i);
                     if (!$this->useInnerArray) {
                         $tempRow[$this->fieldInfo[$i]['name']] = $theResult;
                     } else {
                         $tempRow[$this->fieldInfo[$i]['name']] = array($theResult);
                     }
                     if ($this->fieldInfo[$i]['name'] == $this->primaryKeyField) {
                         $currentKey = $theResult;
                     }
                 }
                 if ($this->genericKeys || $this->primaryKeyField == '') {
                     $this->currentData[] = $tempRow;
                 } else {
                     $this->currentData[$currentKey] = $tempRow;
                 }
             }
             break;
         default:
             return new FX_Error("The action requested ({$action}) is not supported by FileMaker under ODBC via FX.php.");
             break;
     }
     $this->fxError = 0;
     return true;
 }
Example #9
0
 function _initrs()
 {
     global $ADODB_COUNTRECS;
     $this->_numOfRows = $ADODB_COUNTRECS ? @odbc_num_rows($this->_queryID) : -1;
     $this->_numOfFields = @odbc_num_fields($this->_queryID);
     // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0
     if ($this->_numOfRows == 0) {
         $this->_numOfRows = -1;
     }
     //$this->useFetchArray = $this->connection->useFetchArray;
     $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
 }
Example #10
0
 function sql_query($query = "", $transaction = FALSE)
 {
     if ($query != "") {
         $this->num_queries++;
         if ($transaction == BEGIN_TRANSACTION && !$this->in_transaction) {
             if (!odbc_autocommit($this->db_connect_id, false)) {
                 return false;
             }
             $this->in_transaction = TRUE;
         }
         if (preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?\$/s", $query, $limits)) {
             $query = $limits[1];
             if (!empty($limits[2])) {
                 $row_offset = $limits[4] ? $limits[3] : "";
                 $num_rows = $limits[4] ? $limits[4] : $limits[3];
                 $query = "TOP " . ($row_offset + $num_rows) . $query;
             }
             $this->result = odbc_exec($this->db_connect_id, "SELECT {$query}");
             if ($this->result) {
                 if (empty($this->field_names[$this->result])) {
                     for ($i = 1; $i < odbc_num_fields($this->result) + 1; $i++) {
                         $this->field_names[$this->result][] = odbc_field_name($this->result, $i);
                         $this->field_types[$this->result][] = odbc_field_type($this->result, $i);
                     }
                 }
                 $this->current_row[$this->result] = 0;
                 $this->result_rowset[$this->result] = array();
                 $row_outer = isset($row_offset) ? $row_offset + 1 : 1;
                 $row_outer_max = isset($num_rows) ? $row_offset + $num_rows + 1 : 1000000000.0;
                 $row_inner = 0;
                 while (odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max) {
                     for ($j = 0; $j < count($this->field_names[$this->result]); $j++) {
                         $this->result_rowset[$this->result][$row_inner][$this->field_names[$this->result][$j]] = stripslashes(odbc_result($this->result, $j + 1));
                     }
                     $row_outer++;
                     $row_inner++;
                 }
                 $this->num_rows[$this->result] = count($this->result_rowset[$this->result]);
             }
         } else {
             if (eregi("^INSERT ", $query)) {
                 $this->result = odbc_exec($this->db_connect_id, $query);
                 if ($this->result) {
                     $result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
                     if ($result_id) {
                         if (odbc_fetch_row($result_id)) {
                             $this->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
                             $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
                         }
                     }
                 }
             } else {
                 $this->result = odbc_exec($this->db_connect_id, $query);
                 if ($this->result) {
                     $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
                 }
             }
         }
         if (!$this->result) {
             if ($this->in_transaction) {
                 odbc_rollback($this->db_connect_id);
                 odbc_autocommit($this->db_connect_id, true);
                 $this->in_transaction = FALSE;
             }
             return false;
         }
         if ($transaction == END_TRANSACTION && $this->in_transaction) {
             $this->in_transaction = FALSE;
             if (!odbc_commit($this->db_connect_id)) {
                 odbc_rollback($this->db_connect_id);
                 odbc_autocommit($this->db_connect_id, true);
                 return false;
             }
             odbc_autocommit($this->db_connect_id, true);
         }
         odbc_free_result($this->result);
         return $this->result;
     } else {
         if ($transaction == END_TRANSACTION && $this->in_transaction) {
             $this->in_transaction = FALSE;
             if (!@odbc_commit($this->db_connect_id)) {
                 odbc_rollback($this->db_connect_id);
                 odbc_autocommit($this->db_connect_id, true);
                 return false;
             }
             odbc_autocommit($this->db_connect_id, true);
         }
         return true;
     }
 }
 function msaccess_data()
 {
     if (($this->error = $this->checkCredentials()) != "") {
         return $this->error;
     }
     if (!($con = odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . $this->database_name, $this->username, $this->password))) {
         return odbc_errormsg($conn);
     }
     if (!($res = odbc_exec($con, $this->query))) {
         return "Query Failed";
     }
     $i = 0;
     $this->data = array();
     $col = odbc_num_fields($res);
     for ($f = 1; $f <= $col; $f++) {
         $key_arr[] = odbc_field_name($res, $f);
     }
     while ($thisrow = odbc_fetch_array($res)) {
         $this->data[$i] = array();
         foreach ($key_arr as $key) {
             $this->data[$i][$key] = $thisrow[$key];
         }
         $i++;
     }
     odbc_close($con);
 }
Example #12
0
 function _initrs()
 {
     $this->_numOfRows = @odbc_num_rows($this->_queryID);
     $this->_numOfFields = @odbc_num_fields($this->_queryID);
 }
function sql_fetch_object(&$res, $nr = 0)
{
    global $dbtype;
    switch ($dbtype) {
        case "MySQL":
            $row = mysql_fetch_object($res);
            if ($row) {
                return $row;
            } else {
                return false;
            }
            break;
        case "mSQL":
            $row = msql_fetch_object($res);
            if ($row) {
                return $row;
            } else {
                return false;
            }
            break;
        case "postgres":
        case "postgres_local":
            if ($res->get_total_rows() > $res->get_fetched_rows()) {
                $row = pg_fetch_object($res->get_result(), $res->get_fetched_rows());
                $res->increment_fetched_rows();
                if ($row) {
                    return $row;
                } else {
                    return false;
                }
            } else {
                return false;
            }
            break;
        case "ODBC":
            $result = odbc_fetch_row($res, $nr);
            if (!$result) {
                return false;
            }
            $nf = odbc_num_fields($res);
            /* Field numbering starts at 1 */
            for ($count = 1; $count < $nf + 1; $count++) {
                $field_name = odbc_field_name($res, $count);
                $field_value = odbc_result($res, $field_name);
                $row->{$field_name} = $field_value;
            }
            return $row;
            break;
        case "ODBC_Adabas":
            $result = odbc_fetch_row($res, $nr);
            if (!$result) {
                return false;
            }
            $nf = count($result) + 2;
            /* Field numbering starts at 1 */
            for ($count = 1; $count < $nf; $count++) {
                $field_name = odbc_field_name($res, $count);
                $field_value = odbc_result($res, $field_name);
                $row->{$field_name} = $field_value;
            }
            return $row;
            break;
        case "Interbase":
            $orow = ibase_fetch_object($res);
            if ($orow) {
                $arow = get_object_vars($orow);
                while (list($name, $key) = each($arow)) {
                    $name = strtolower($name);
                    $row->{$name} = $key;
                }
                return $row;
            } else {
                return false;
            }
            break;
        case "Sybase":
            $row = sybase_fetch_object($res);
            return $row;
            break;
    }
}
Example #14
0
 function sql_query($query = "", $transaction = FALSE)
 {
     //
     // Remove any pre-existing queries
     //
     unset($this->query_result);
     unset($this->row);
     if ($query != "") {
         $this->num_queries++;
         if (!eregi("^INSERT ", $query)) {
             if (eregi("LIMIT", $query)) {
                 preg_match("/^(.*)LIMIT ([0-9]+)[, ]*([0-9]+)*/s", $query, $limits);
                 $query = $limits[1];
                 if ($limits[3]) {
                     $row_offset = $limits[2];
                     $num_rows = $limits[3];
                 } else {
                     $row_offset = 0;
                     $num_rows = $limits[2];
                 }
                 $query .= " FETCH FIRST " . ($row_offset + $num_rows) . " ROWS ONLY OPTIMIZE FOR " . ($row_offset + $num_rows) . " ROWS";
                 $this->query_result = odbc_exec($this->db_connect_id, $query);
                 $query_limit_offset = $row_offset;
                 $this->result_numrows[$this->query_result] = $num_rows;
             } else {
                 $this->query_result = odbc_exec($this->db_connect_id, $query);
                 $row_offset = 0;
                 $this->result_numrows[$this->query_result] = 5000000.0;
             }
             $result_id = $this->query_result;
             if ($this->query_result && eregi("^SELECT", $query)) {
                 for ($i = 1; $i < odbc_num_fields($result_id) + 1; $i++) {
                     $this->result_field_names[$result_id][] = odbc_field_name($result_id, $i);
                 }
                 $i = $row_offset + 1;
                 $k = 0;
                 while (odbc_fetch_row($result_id, $i) && $k < $this->result_numrows[$result_id]) {
                     for ($j = 1; $j < count($this->result_field_names[$result_id]) + 1; $j++) {
                         $this->result_rowset[$result_id][$k][$this->result_field_names[$result_id][$j - 1]] = odbc_result($result_id, $j);
                     }
                     $i++;
                     $k++;
                 }
                 $this->result_numrows[$result_id] = $k;
                 $this->row_index[$result_id] = 0;
             } else {
                 $this->result_numrows[$result_id] = @odbc_num_rows($result_id);
                 $this->row_index[$result_id] = 0;
             }
         } else {
             if (eregi("^(INSERT|UPDATE) ", $query)) {
                 $query = preg_replace("/\\\\'/s", "''", $query);
             }
             $this->query_result = odbc_exec($this->db_connect_id, $query);
             if ($this->query_result) {
                 $sql_id = "VALUES(IDENTITY_VAL_LOCAL())";
                 $id_result = odbc_exec($this->db_connect_id, $sql_id);
                 if ($id_result) {
                     $row_result = odbc_fetch_row($id_result);
                     if ($row_result) {
                         $this->next_id[$this->query_result] = odbc_result($id_result, 1);
                     }
                 }
             }
             odbc_commit($this->db_connect_id);
             $this->query_limit_offset[$this->query_result] = 0;
             $this->result_numrows[$this->query_result] = 0;
         }
         return $this->query_result;
     } else {
         return false;
     }
 }
             $data[] = $row;
         }
     }
     mysql_free_result($result);
     mysql_close($connection);
     break;
 case 'ORACLE':
     $connect = odbc_connect($servername, $username, $password);
     $result = odbc_exec($connect, $sql);
     # return error if query failed
     if (!$result) {
         print json_encode(array('error' => array('message' => odbc_errormsg($connect), 'code' => odbc_error($connect))));
         exit;
     } else {
         #odbc returns results as strings, so get datatype fields here
         for ($x = 1; $x <= odbc_num_fields($result); $x++) {
             $types[] = odbc_field_type($result, $x);
         }
         while ($row = odbc_fetch_array($result)) {
             $x = 0;
             #convert each string to its actual datatype, so easily usable in javascript
             foreach ($row as $key => $value) {
                 switch ($types[$x]) {
                     case 'NUMBER':
                         $row[$key] = $value + 0;
                         break;
                     default:
                         break;
                 }
                 $x++;
             }
Example #16
0
 /**
  * Get the rows returned from a SELECT query.
  *
  * @param  resource		The query result pointer
  * @param  ?integer		Whether to start reading from (NULL: irrelevant for this forum driver)
  * @return array			A list of row maps
  */
 function db_get_query_rows($results, $start = NULL)
 {
     $out = array();
     $i = 0;
     $num_fields = odbc_num_fields($results);
     $types = array();
     $names = array();
     for ($x = 1; $x <= $num_fields; $x++) {
         $types[$x] = odbc_field_type($results, $x);
         $names[$x] = odbc_field_name($results, $x);
     }
     while (odbc_fetch_row($results)) {
         if (is_null($start) || $i >= $start) {
             $newrow = array();
             for ($j = 1; $j <= $num_fields; $j++) {
                 $v = odbc_result($results, $j);
                 $type = $types[$j];
                 $name = strtolower($names[$j]);
                 if ($type == 'INTEGER' || $type == 'SMALLINT' || $type == 'UINTEGER') {
                     if (!is_null($v)) {
                         $newrow[$name] = intval($v);
                     } else {
                         $newrow[$name] = NULL;
                     }
                 } else {
                     $newrow[$name] = $v;
                 }
             }
             $out[] = $newrow;
         }
         $i++;
     }
     odbc_free_result($results);
     //	echo '<p>End '.microtime(false);
     return $out;
 }
 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();
     }
 }
Example #18
0
                 } else {
                     $q_result .= "<p style=\"padding:0;margin:20px 6px 0 6px;\">" . $query . ";&nbsp;&nbsp;&nbsp;\n\t\t\t\t\t\t\t<span class=\"gaya\">[</span> error <span class=\"gaya\">]</span></p>";
                 }
             }
         }
     }
 } elseif (isset($_REQUEST['odbccon']) && ($con = odbc_connect($odbcdsn, $odbcuser, $odbcpass))) {
     if (isset($_REQUEST['sqlcode'])) {
         $sqls = ss($_REQUEST['sqlcode']);
         $querys = explode(";", $sqls);
         foreach ($querys as $query) {
             if (trim($query) != "") {
                 $hasil = odbc_exec($con, $query);
                 if ($hasil) {
                     $q_result .= "<p style=\"padding:0;margin:20px 6px 0 6px;\">" . $query . ";&nbsp;&nbsp;&nbsp;\n\t\t\t\t\t\t<span class=\"gaya\">[</span> ok <span class=\"gaya\">]</span></p>\n\t\t\t\t\t\t<table class=\"explore\" style=\"width:99%;\"><tr>";
                     for ($i = 1; $i <= odbc_num_fields($hasil); $i++) {
                         $q_result .= "<th>" . htmlspecialchars(odbc_field_name($hasil, $i)) . "</th>";
                     }
                     $q_result .= "</tr>";
                     while ($rows = odbc_fetch_array($hasil)) {
                         $q_result .= "<tr>";
                         foreach ($rows as $r) {
                             if ($r == "") {
                                 $dataz = " ";
                             } else {
                                 $dataz = $r;
                             }
                             $q_result .= "<td>" . htmlspecialchars($dataz) . "</td>";
                         }
                         $q_result .= "</tr>";
                     }
Example #19
0
 /**
  * ODBC::getFieldNames()
  *
  * Return the field names of the table
  *
  * @param string $table: the table where we should fetch the field names from
  * @return array
  * @access public
  * @author Teye Heimans
  */
 function getFieldNames($table)
 {
     $sql = odbc_columns($this->_conn);
     $result = array();
     $num = odbc_num_fields($sql);
     for ($i = 1; $i <= $num; $i++) {
         $result[$i - 1] = odbc_field_name($sql, $i);
     }
     $num = odbc_num_rows($sql);
     echo "Aantal rows: {$num}<br />\n";
     for ($i = 0; $i <= $num; $i++) {
         echo odbc_result($sql, 4) . "<br >\n";
     }
     return $result;
 }
Example #20
0
 /**
  * Get the number of columns in the result set
  *
  * @return int
  */
 public function columnCount()
 {
     switch ($this->mode) {
         case "mysql":
             $columns = $this->result->field_count;
             break;
         case "postgres":
         case "redshift":
             $columns = pg_num_fields($this->result);
             break;
         case "odbc":
             $columns = odbc_num_fields($this->result);
             break;
         case "sqlite":
             $columns = $this->result->numColumns();
             break;
         case "mssql":
             $columns = mssql_num_fields($this->result);
             break;
     }
     if ($columns === false || $columns < 0) {
         throw new \Exception("Failed to get the column count from the result set");
     }
     return $columns;
 }
Example #21
0
    case "cultural":
        $table = "cultural";
        $sqlselect = "SELECT " . $table . ".cultural_price, " . $table . ".cultural_type, " . $table . ".name, " . $table . ".phone, " . $table . ".address, " . $table . ".neighborhood, " . $table . ".city,\n                 reviewer.first_name, reviewer.last_name , review.review_rank, review.comments";
        $type_sql = $table . ".cultural_type = '" . $type . "'";
        $level_sql = $table . ".cultural_price = '" . $level . "'";
        break;
    case "outdoors":
        $table = "outdoors";
        $sqlselect = "SELECT " . $table . ".outdoors_level, " . $table . ".outdoors_type, " . $table . ".name, " . $table . ".phone, " . $table . ".address, " . $table . ".city, reviewer.first_name, \n                 reviewer.last_name, review.review_rank, review.comments";
        $type_sql = $table . ".outdoors_type = '" . $type . "'";
        $level_sql = $table . ".outdoors_level = '" . $level . "'";
        break;
}
$rating_sql = "review.review_rank = " . $rating;
$city_sql = $table . ".city='" . $city . "'";
$sqlfrom = "FROM reviewer INNER JOIN (" . $table . " INNER JOIN review \n                                                 ON " . $table . ".id_number = review.id_number)\n                          ON reviewer.user_name = review.user_name";
$sqlwhere = "WHERE ((" . $type_sql . ") AND (" . $level_sql . ") AND (" . $rating_sql . ") AND (" . $city_sql . "))";
$sql = $sqlselect . " " . $sqlfrom . " " . $sqlwhere;
$conn = odbc_connect('finalproject', '', '') or die('Could Not Connect to ODBC Database!');
echo "sql = " . $sql . "<br>";
$result = odbc_exec($conn, $sql) or die(odbc_errormsg());
while (odbc_fetch_row($result)) {
    for ($i = 1; $i <= odbc_num_fields($result); $i++) {
        echo "result " . $i . " = " . odbc_result($result, $i) . "<br>";
    }
}
odbc_close($conn);
?>

</body>
</html>
Example #22
0
 /**
  *
  */
 function getFieldCount()
 {
     return odbc_num_fields($this->query);
 }
Example #23
0
function make_results_table($result, $show_rowid, $table_name)
{
    if ($result === false) {
        ?>
		<div class="error_message">
			<?php 
        echo odbc_error() . ": " . odbc_errormsg();
        ?>
		</div>
<?php 
    } else {
        ?>
		<!-- TODO add edit/delete buttons for each row -->
		<!-- TODO field editing on click [?] -->
		<!-- TODO think about NULL -->
		<table class="results_table">
			<tr>
<?php 
        $fields_count = odbc_num_fields($result);
        $rowid_index = -1;
        for ($i = 1; $i <= $fields_count; ++$i) {
            $field_name = odbc_field_name($result, $i);
            if ($field_name == "ROWID" && !$show_rowid) {
                $rowid_index = $i - 1;
                continue;
            }
            echo "<th>" . $field_name . "</th>";
        }
        ?>
			</tr>
<?php 
        function treat_result($res)
        {
            if ($res == '') {
                return "&nbsp;";
            }
            return htmlspecialchars($res);
        }
        $res = array();
        $current_rowid = null;
        while (odbc_fetch_into($result, $res)) {
            $current_rowid = treat_result($res[$rowid_index]);
            echo "<tr id='row_" . $current_rowid . "'>";
            $controls = true;
            for ($i = 0; $i < $fields_count; ++$i) {
                if ($i == $rowid_index) {
                    continue;
                }
                echo "<td>" . treat_result($res[$i]);
                if ($controls && $table_name != null) {
                    $controls = false;
                    echo "<div class='row_control'>";
                    echo "<a class='button delete' href='javascript:delete_entry(\"" . $current_rowid . "\");'></a>";
                    echo "<a class='button edit' href='?tables&action=add_entry&target=" . $table_name . "&rowid=" . $current_rowid . "'></a>";
                    echo "</div>";
                }
                echo "</td>";
            }
            echo "</tr>";
        }
        ?>
		</table>
<?php 
    }
}
Example #24
0
 function write_data_odbc($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 = odbc_num_rows($result);
     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);
     }
     $i_num_fields = odbc_num_fields($result);
     for ($i = 0; $i < $i_num_fields; $i++) {
         $ary_type[$i] = odbc_field_type($result, $i + 1);
         $ary_name[$i] = odbc_field_name($result, $i + 1);
     }
     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);
 }
 /**
  * Number of fields in the result set
  *
  * @return	int
  */
 public function num_fields()
 {
     return @odbc_num_fields($this->result_id);
 }
 public function numFields()
 {
     if (!empty($this->query)) {
         return odbc_num_fields($this->query);
     } else {
         return 0;
     }
 }
Example #27
0
 function numCols($result)
 {
     $cols = @odbc_num_fields($result);
     if (!$cols) {
         return $this->odbcRaiseError();
     }
     return $cols;
 }
Example #28
0
        </tr>
        <tr>
          <td><?php 
    echo $name = odbc_result($tableexec, "TABLE_NAME");
    ?>
</td>
          <td><?php 
    echo odbc_result($tableexec, "REMARKS");
    ?>
</td>
<?php 
    // number of columns.  Need to look them up first.
    $colexec = odbc_columns($conn, "", "", $name);
    ?>
          <td><?php 
    echo odbc_num_fields($colexec);
    ?>
</td>
        </tr>
        <tr>
          <td align="right" colspan="3">
            <table border="0" cellpadding="10" cellspacing="0">
              <tr>
                <td>
                  <table border="1">
                    <tr bgcolor="yellow">
                      <th>Column Name</th><th>Description</th>
                      <th>Data Type</th><th>Size</th>
                    </tr>
<?php 
    // loop through columns
Example #29
0
 /**
  * Returns metadata for all columns in a result set.
  * @return array
  */
 public function getColumnsMeta()
 {
     $count = odbc_num_fields($this->resultSet);
     $res = array();
     for ($i = 1; $i <= $count; $i++) {
         $res[] = array('name' => odbc_field_name($this->resultSet, $i), 'table' => NULL, 'fullname' => odbc_field_name($this->resultSet, $i), 'nativetype' => odbc_field_type($this->resultSet, $i));
     }
     return $res;
 }
Example #30
0
 /**
  * Returns information about a table or a result set
  *
  * @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()
  * @since Method available since Release 1.7.0
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         $id = @odbc_exec($this->connection, "SELECT * FROM {$result}");
         if (!$id) {
             return $this->odbcRaiseError();
         }
         $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->odbcRaiseError(DB_ERROR_NEED_MORE_DATA);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $count = @odbc_num_fields($id);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     for ($i = 0; $i < $count; $i++) {
         $col = $i + 1;
         $res[$i] = array('table' => $got_string ? $case_func($result) : '', 'name' => $case_func(@odbc_field_name($id, $col)), 'type' => @odbc_field_type($id, $col), 'len' => @odbc_field_len($id, $col), '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) {
         @odbc_free_result($id);
     }
     return $res;
 }