/** * 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); }
public function fetchFields() { $fields = array(); for ($i = 0; $i < odbc_num_fields($this->result); ++$i) { $fields[] = odbc_field_name($this->result, $i); } return $fields; }
/** * 表的字段列表 * * 生成一个表字段列名称的数组,修复默认 CI_DB_odbc_result->list_fields()的错误 * * @access public * @return array */ function list_fields() { $field_names = array(); for ($i = 1; $i <= $this->num_fields(); $i++) { $field_names[] = odbc_field_name($this->result_id, $i); } return $field_names; }
function _fetch_array($bdid) { global $ODBC_ID, $last_odbc_result; if (odbc_fetch_into($bdid, $res_odbc_row)) { foreach ($res_odbc_row as $k => $v) { $data_odbc_row[odbc_field_name($bdid, $k + 1)] = $v; } return $data_odbc_row; } else { return False; } }
/** Thanks to ironhacker (ironhacker at users.sourceforge.net) for this! */ function odbc_fetch_array_hack($result, $rownumber = -1) { $rs_assoc = array(); if (PHP_VERSION > "4.1") { if ($rownumber < 0) { odbc_fetch_into($result, &$rs); } else { odbc_fetch_into($result, &$rs, $rownumber); } } else { odbc_fetch_into($result, $rownumber, &$rs); } foreach ($rs as $key => $value) { $rs_assoc[odbc_field_name($result, $key + 1)] = $value; } return $rs_assoc; }
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; }
/** * 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)); } }
/** * Result - array * * subsititutes the odbc_fetch_array function when * not available (odbc_fetch_array requires unixODBC) * * @access private * @return array */ function _odbc_fetch_array(&$odbc_result) { $rs = array(); $rs_assoc = FALSE; if (odbc_fetch_into($odbc_result, $rs)) { $rs_assoc = array(); foreach ($rs as $k => $v) { $field_name = odbc_field_name($odbc_result, $k + 1); $rs_assoc[$field_name] = $v; } } return $rs_assoc; }
/** * 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; }
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); }
/** * Field data * * Generates an array of objects containing field meta-data * * @access public * @return array */ function field_data() { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { $F = new CI_DB_field(); $F->name = odbc_field_name($this->result_id, $i); $F->type = odbc_field_type($this->result_id, $i); $F->max_length = odbc_field_len($this->result_id, $i); $F->primary_key = 0; $F->default = ''; $retval[] = $F; } return $retval; }
/** * 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_field_name($sqltype, $result, $i) { if ($sqltype == 'mysql') { if (class_exists('mysqli_result')) { $z = $result->fetch_field(); return $z->name; } elseif (function_exists('mysql_field_name')) { return mysql_field_name($result, $i); } } elseif ($sqltype == 'mssql') { if (function_exists('sqlsrv_field_metadata')) { $metadata = sqlsrv_field_metadata($result); if (is_array($metadata)) { $metadata = $metadata[$i]; } if (is_array($metadata)) { return $metadata['Name']; } } elseif (function_exists('mssql_field_name')) { return mssql_field_name($result, $i); } } elseif ($sqltype == 'pgsql') { return pg_field_name($result, $i); } elseif ($sqltype == 'oracle') { return oci_field_name($result, $i + 1); } elseif ($sqltype == 'sqlite3') { return $result->columnName($i); } elseif ($sqltype == 'sqlite') { return sqlite_field_name($result, $i); } elseif ($sqltype == 'odbc') { return odbc_field_name($result, $i + 1); } elseif ($sqltype == 'pdo') { $res = $result->getColumnMeta($i); return $res['name']; } }
function fetchInto($result, &$row, $fetchmode, $rownum = null) { $row = array(); if ($rownum !== null) { $rownum++; // ODBC first row is 1 if (version_compare(phpversion(), '4.2.0', 'ge')) { $cols = odbc_fetch_into($result, $row, $rownum); } else { $cols = odbc_fetch_into($result, $rownum, $row); } } else { $cols = odbc_fetch_into($result, $row); } if (!$cols) { /* XXX FIXME: doesn't work with unixODBC and easysoft (get corrupted $errno values) if ($errno = odbc_error($this->connection)) { return $this->RaiseError($errno); }*/ return null; } if ($fetchmode !== DB_FETCHMODE_ORDERED) { for ($i = 0; $i < count($row); $i++) { $colName = odbc_field_name($result, $i + 1); $a[$colName] = $row[$i]; } if ($this->options['optimize'] == 'portability') { $a = array_change_key_case($a, CASE_LOWER); } $row = $a; } return DB_OK; }
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; } }
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 " "; } 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 } }
/** * Field data * * Generates an array of objects containing field meta-data * * @return array */ public function field_data() { $retval = array(); for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++) { $retval[$i] = new stdClass(); $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index); $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index); $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index); $retval[$i]->primary_key = 0; $retval[$i]->default = ''; } return $retval; }
/** * */ function getFieldNames() { $result = array(); for ($i = 1; $i <= odbc_num_fields($this->query); $i++) { $result[] = odbc_field_name($this->query, $i); } return $result; }
$q_result .= "<p style=\"padding:0;margin:20px 6px 0 6px;\">" . $query . "; \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 . "; \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>"; } $q_result .= "</table>";
function &FetchField($fieldOffset = -1) { $off = $fieldOffset + 1; // offsets begin at 1 $o = new ADOFieldObject(); $o->name = @odbc_field_name($this->_queryID, $off); $o->type = @odbc_field_type($this->_queryID, $off); $o->max_length = @odbc_field_len($this->_queryID, $off); return $o; }
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; } }
/** * Returns an array of the fields in given table name. * * @param Model $model Model object to describe * @return array Fields in table. Keys are name and type */ function &describe(&$model) { $cache = parent::describe($model); if ($cache != null) { return $cache; } $fields = array(); $sql = 'SELECT * FROM ' . $this->fullTableName($model); $result = odbc_exec($this->connection, $sql); $count = odbc_num_fields($result); for ($i = 1; $i <= $count; $i++) { $cols[$i - 1] = odbc_field_name($result, $i); } foreach ($cols as $column) { $type = odbc_field_type(odbc_exec($this->connection, "SELECT " . $column . " FROM " . $this->fullTableName($model)), 1); $fields[$column] = array('type' => $type); } $this->__cacheDescription($model->tablePrefix . $model->table, $fields); return $fields; }
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); }
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; } }
function &FetchField($fieldOffset = -1) { $off = $fieldOffset + 1; // offsets begin at 1 $o = new ADOFieldObject(); $o->name = @odbc_field_name($this->_queryID, $off); $o->type = @odbc_field_type($this->_queryID, $off); $o->max_length = @odbc_field_len($this->_queryID, $off); if (ADODB_ASSOC_CASE == 0) { $o->name = strtolower($o->name); } else { if (ADODB_ASSOC_CASE == 1) { $o->name = strtoupper($o->name); } } return $o; }
public function columns() { if (empty($this->query)) { return false; } $columns = array(); $num_fields = $this->num_fields(); for ($i = 0; $i < $num_fields; $i++) { $columns[] = odbc_field_name($this->query, $i); } return $columns; }
/** * Fetch a row and insert the data into an existing array. * * Formating of the array and the data therein are configurable. * See DB_result::fetchInto() for more information. * * @param resource $result query result identifier * @param array $arr (reference) array where data from the row * should be placed * @param int $fetchmode how the resulting array should be indexed * @param int $rownum the row number to fetch * * @return mixed DB_OK on success, null when end of result set is * reached or on failure * * @see DB_result::fetchInto() * @access private */ function fetchInto($result, &$arr, $fetchmode, $rownum = null) { $arr = array(); if ($rownum !== null) { $rownum++; // ODBC first row is 1 if (version_compare(phpversion(), '4.2.0', 'ge')) { $cols = @odbc_fetch_into($result, $arr, $rownum); } else { $cols = @odbc_fetch_into($result, $rownum, $arr); } } else { $cols = @odbc_fetch_into($result, $arr); } if (!$cols) { /* XXX FIXME: doesn't work with unixODBC and easysoft (get corrupted $errno values) if ($errno = @odbc_error($this->connection)) { return $this->RaiseError($errno); }*/ return null; } if ($fetchmode !== DB_FETCHMODE_ORDERED) { for ($i = 0; $i < count($arr); $i++) { $colName = @odbc_field_name($result, $i + 1); $a[$colName] = $arr[$i]; } if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) { $a = array_change_key_case($a, CASE_LOWER); } $arr = $a; } if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { $this->_rtrimArrayValues($arr); } if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { $this->_convertNullArrayValuesToEmpty($arr); } return DB_OK; }
/** * Converts row fields to names if FETCHMODE_ASSOC is set. * * @param array& Row to convert. * * @return array& Converted row. */ protected function checkFetchMode(&$row) { if ($this->fetchmode == ResultSet::FETCHMODE_ASSOC) { $newrow = array(); for ($i = 0, $n = count($row); $i < $n; $i++) { $colname = @odbc_field_name($this->result->getHandle(), $i + 1); if ($this->lowerAssocCase) { $colname = strtolower($colname); } $newrow[$colname] = $row[$i]; } $row =& $newrow; } return $row; }
/** * 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; }
/** * 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; }