function check_max_field_lengths($fields_with_lengths, $POST) { $errors = array(); foreach ($fields_with_lengths as $fieldname) { $errors[] = odbc_field_len($_POST[$fieldname]); } return $errors; }
/** * 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 stdClass(); $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; }
/** * 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; }
public function columnData() { if (empty($this->query)) { return false; } $columns = array(); for ($i = 0, $index = 1, $c = $this->num_fields(); $i < $c; $i++, $index++) { $columns[$i] = new stdClass(); $columns[$i]->name = odbc_field_name($this->query, $index); $columns[$i]->type = odbc_field_type($this->query, $index); $columns[$i]->max_length = odbc_field_len($this->query, $index); $columns[$i]->primary_key = 0; $columns[$i]->default = ''; } return $columns; }
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; }
\tc CHAR(123), \tvc VARCHAR(125) ) EOSQL; odbc_exec($conn, "IF OBJECT_ID('php_types') IS NOT NULL DROP TABLE php_types") or die(odbc_errormsg()); odbc_exec($conn, $sql) or die(odbc_errormsg()); $sql = "select * from php_types"; echo "Query: {$sql}\n"; $result = odbc_exec($conn, $sql) or die(odbc_errormsg()); $all = array('ui' => 'smallint-5', 'i' => 'int-10', 'ti' => 'tinyint-3', 'c' => 'char-123', 'vc' => 'varchar-125'); $err = ''; $ok = 0; for ($i = 1; $i <= odbc_num_fields($result); $i++) { $name = odbc_field_name($result, $i); $type = odbc_field_type($result, $i); $len = odbc_field_len($result, $i); echo "column {$name} type {$type} len {$len}\n"; $type = strtolower($type); if ($all[$name] != "{$type}-{$len}") { $err .= "Invalid column {$name}\n"; } else { ++$ok; } } if ($ok != 5) { $err .= "Expected 5 columns\n"; } if ($err) { echo "{$err}"; exit(1); }
/** * Returns metadata for all columns in a result set. * * @return array */ public function getColumnsMeta() { $count = odbc_num_fields($this->resultSet); $meta = array(); for ($i = 1; $i <= $count; $i++) { // items 'name' and 'table' are required $meta[] = array('name' => odbc_field_name($this->resultSet, $i), 'table' => NULL, 'type' => odbc_field_type($this->resultSet, $i), 'length' => odbc_field_len($this->resultSet, $i), 'scale' => odbc_field_scale($this->resultSet, $i), 'precision' => odbc_field_precision($this->resultSet, $i)); } return $meta; }
public function columnData($col = '') { if (empty($this->query)) { return false; } $columns = []; $count = $this->numFields(); for ($i = 0, $index = 1; $i < $count; $i++, $index++) { $fieldName = odbc_field_name($this->query, $index); $columns[$fieldName] = new \stdClass(); $columns[$fieldName]->name = $fieldName; $columns[$fieldName]->type = odbc_field_type($this->query, $index); $columns[$fieldName]->maxLength = odbc_field_len($this->query, $index); $columns[$fieldName]->primaryKey = NULL; $columns[$fieldName]->default = NULL; } if (isset($columns[$col])) { return $columns[$col]; } return $columns; }
$result = odbc_exec($connection, $sql); if ($result) { $nCols = odbc_num_fields($result); odbc_fetch_row($result, 0); } else { $nCols = 0; $status = odbc_errormsg($connection); } echo "\"metadata\":["; for ($i = 1; $i <= $nCols; $i++) { echo "{\"type\":"; echo json_encode(odbc_field_type($result, $i)); echo ",\"name\":"; echo json_encode(odbc_field_name($result, $i)); echo ",\"len\":"; echo json_encode(odbc_field_len($result, $i)); echo ",\"precision\":"; echo json_encode(odbc_field_precision($result, $i)); echo ",\"scale\":"; echo json_encode(odbc_field_scale($result, $i)); if ($i < $nCols) { echo "},"; } else { echo "}"; } } echo "],"; $result = odbc_exec($connection, Grammar::count($_POST["table"])); if ($result && odbc_fetch_row($result)) { echo "\"totalRecords\":" . odbc_result($result, 1) . ","; } else {
<?php $info = odbc_exec($conn, "select * from php_test"); $numfields = odbc_num_fields($info); for ($i = 1; $i <= $numfields; $i++) { ?> <tr> <td><?php echo odbc_field_name($info, $i); ?> </td> <td><?php echo odbc_field_type($info, $i); ?> </td> <td><?php echo odbc_field_len($info, $i); ?> </td> </tr> <?php } odbc_free_result($info); ?> </table> Inserting data: <?php echo "{$gif1file} - {$gif2file} - {$gif3file}"; odbc_free_result($res); $res = odbc_prepare($conn, "insert into php_test values(?,?)"); if ($gif1file != "none") {
function form_add($table) { global $dsn, $dbConn; open_db(); $tabs = odbc_tables($dbConn); $tables = array(); while (odbc_fetch_row($tabs)) { if (odbc_result($tabs, "TABLE_TYPE") == "TABLE") { $table_name = odbc_result($tabs, "TABLE_NAME"); if ($table_name == $table) { $tables["{$table_name}"] = array(); $cols = odbc_exec($dbConn, 'select * from ' . $table_name . ' where 1=2'); $ncols = odbc_num_fields($cols); echo "<form action='new.php?table=" . $table . "' id='" . $table . "_form' method='POST'>"; echo "<fieldset id='edit-fields-" . $table . "'>\n"; for ($n = 1; $n <= $ncols; $n++) { $field_name = odbc_field_name($cols, $n); echo "<div class='field'>\n"; echo "<label for='" . $field_name . "'>" . $field_name . "</label>\n"; if (odbc_field_len($cols, $n) > 50) { $field_len = 50; } else { $field_len = odbc_field_len($cols, $n); } echo "<input class='required number' id='" . $field_name . "' name='" . $field_name . "' size='" . $field_len . "' type='text' />\n"; echo "</div>\n"; } echo "<div class='field'>\n"; echo "</div>\n"; echo "</fieldset>\n"; echo "<div class='buttons'>\n"; echo "<input class='submit' type='submit' value='Add' />\n"; echo "</div>\n"; echo "</form>"; } } } close_db(); return true; }
public function odbc_getPossibleLongResult(&$resultset, $fieldID) { $longValue = ""; $longValue = odbc_result($resultset, $fieldID); if ($this->enable_lrl && $longValue != "" && odbc_field_len($resultset, $fieldID) > ini_get("odbc.defaultlrl")) { while (($chunk = odbc_result($resultset, $fieldID)) !== FALSE) { $longValue .= $chunk; } } return $longValue; }
function vty_field_len($list,$i){ switch($this->vtAdi){ case 'mysql': return mysql_field_len($list,$i); break; case 'odbc': return odbc_field_len($list,$i); break; case 'mssql': return mssql_field_length($list,$i); break; case 'postgresql': pg_field_len($list,$i); break; } }
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; }
function ecritFormulaire($pTable, $pNomForm, $pFichAction, $pMethode, $pFichier) { //écrit dans un fichier le code HTML produisant un formulaire pour les champs d'une table d'une base $result = odbc_do($this->connexion, "select * from " . $pTable); //explore les champs de la table //écriture des propriétés du formulaire fputs($pFichier, '<form name="' . $pNomForm . '" method="' . $pMethode . '" action="' . $pFichAction . '">'); //écrit dans le fichier fputs($pFichier, "\n"); //retour à la ligne //parcours des champs de la table for ($i = 1; $i < odbc_num_fields($result) + 1; $i++) { $this->traiteUnChampForm(odbc_field_name($result, $i), odbc_field_type($result, $i), odbc_field_len($result, $i), $pFichier); } //écriture du pied de formulaire avec les boutons correspondants fputs($pFichier, '<label class="titre"></label><div class="zone"><input type="reset" value="annuler"></input><input type="submit"></input></form>'); }
/** * 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; }
<?php include 'connect.inc'; $r = odbc_connect($directdsn, $db_user, $db_pass); //var_dump($r); echo "resource? " . is_resource($r) . "\n"; if (!$r) { echo odbc_errormsg(); exit(1); } $rh = odbc_exec($r, "SELECT * FROM my_table"); if (!$rh) { echo "odbc_exec failed!\n"; echo odbc_errormsg(); echo odbc_close($r); exit(1); } //var_dump($rh); echo "resource? " . is_resource($rh) . "\n"; // odbc_cursor echo odbc_cursor($rh) . "\n"; // fields echo odbc_field_len($rh, 1) . "\n"; echo odbc_field_precision($rh, 2) . "\n"; echo odbc_field_scale($rh, 3) . "\n"; echo odbc_field_name($rh, 2) . "\n"; echo odbc_field_num($rh, 'field2') . "\n"; echo odbc_field_type($rh, 3) . "\n"; echo odbc_close($r);