$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 {
     $status = "Error while trying to count records";
 }
Beispiel #2
0
 /**
  * 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;
 }
<?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);