if (!$r) { echo odbc_errormsg(); exit(1); } $rh = odbc_gettypeinfo($r); echo "resource? " . is_resource($rh) . "\n"; //var_dump($rh); if ($rh == NULL) { echo odbc_errormsg(); exit(1); } while ($rr = odbc_fetch_array($rh)) { // we use ODBC 3, so we differ in column type # for date columns // this is not a bug if ($rr['TYPE_NAME'] == 'datetime' || $rr['TYPE_NAME'] == 'timestamp' || $rr['TYPE_NAME'] == 'date' || $rr['TYPE_NAME'] == 'time') { $rr['DATA_TYPE'] = '(hack)'; $rr['SQL_DATATYPE'] = '(hack)'; } var_dump($rr); } $rh = odbc_gettypeinfo($r, SQL_VARCHAR); echo "resource? " . is_resource($rh) . "\n"; //var_dump($rh); if ($rh == NULL) { echo odbc_errormsg(); exit(1); } while ($rr = odbc_fetch_array($rh)) { var_dump($rr); } echo odbc_close($r);
function Connect() { if ($this->dba_access) { $dsn = isset($this->options["DBADSN"]) ? $this->options["DBADSN"] : ""; $user = isset($this->options["DBAUser"]) ? $this->options["DBAUser"] : ""; $password = isset($this->options["DBAPassword"]) ? $this->options["DBAPassword"] : ""; $persistent = 0; } else { $dsn = $this->database_name; $user = $this->user; $password = $this->password; $persistent = $this->persistent; } if ($this->connection != 0) { if (!strcmp($this->selected_database, $dsn) && !strcmp($this->connected_user, $user) && !strcmp($this->connected_password, $password) && $this->opened_persistent == $persistent) { return 1; } $this->Close(); } $function = $persistent ? "odbc_pconnect" : "odbc_connect"; if (!function_exists($function)) { return $this->SetError("Connect", "ODBC support is not available in this PHP configuration"); } if (($this->connection = @$function($dsn, $user, $password)) <= 0) { return $this->SetODBCError("Connect", "Could not connect to ODBC server", $php_errormsg); } $this->supported_types = array(); $this->type_field_names = array(); $this->type_index = array(); $this->type_property_names = array(); if ($this->get_type_info && function_exists("odbc_gettypeinfo")) { if (!($this->types_result = odbc_gettypeinfo($this->connection))) { $this->SetODBCError("Connect", "Could not obtain the information of supported ODBC data types", $php_errormsg); $this->Close(); return 0; } $properties = odbc_num_fields($this->types_result); for ($property = 1; $property <= $properties; $property++) { $property_name = odbc_field_name($this->types_result, $property); $this->type_property_names[$property_name] = $property - 1; switch ($property) { case 3: $this->size_field = $property_name; break; case 12: $auto_increment_field = $property_name; break; } } for ($type_index = $index = 1; $this->FetchInto($this->types_result, $index, $this->supported_types[$type_index]); $type_index++, $index = $type_index) { $type = intval($this->supported_types[$type_index][$this->type_property_names["DATA_TYPE"]]); if (strcmp($this->supported_types[$type_index][$this->type_property_names[$auto_increment_field]], "1")) { $this->type_index[$type] = $type_index; } } unset($this->supported_types[$type_index]); if (isset($this->options["FreeTypesResult"])) { odbc_free_result($this->types_result); } $this->types_result = 0; } if (!$this->auto_commit && !@odbc_autocommit($this->connection, 0)) { $this->SetODBCError("Connect", "Could not disable transaction auto-commit mode", $php_errormsg); $this->Close(); return 0; } $this->selected_database = $dsn; $this->connected_user = $user; $this->connected_password = $password; $this->opened_persistent = $persistent; return 1; }
/** * Loads the map of ODBC data types to Creole (JDBC) types. * * NOTE: This function cannot map DBMS-specific datatypes. If you use a * driver which implements DBMS-specific datatypes, you will need * to modify/extend this class to add the correct mapping. */ public static function loadTypeMap($conn = null) { if (self::$typeMap !== null && count(self::$typeMap) > 0) { return; } if ($conn == null) { throw new SQLException('No connection specified when loading ODBC type map.'); } self::$typeMap = array(); $result = @odbc_gettypeinfo($conn->getResource()); if ($result === false) { throw new SQLException('Failed to retrieve type info.', $conn->nativeError()); } $rowNum = 1; while (odbc_fetch_row($result, $rowNum++)) { $odbctypeid = odbc_result($result, 'DATA_TYPE'); $odbctypename = odbc_result($result, 'TYPE_NAME'); switch ($odbctypeid) { case SQL_CHAR: self::$typeMap[$odbctypename] = CreoleTypes::CHAR; break; case SQL_VARCHAR: self::$typeMap[$odbctypename] = CreoleTypes::VARCHAR; break; case SQL_LONGVARCHAR: self::$typeMap[$odbctypename] = CreoleTypes::LONGVARCHAR; break; case SQL_DECIMAL: self::$typeMap[$odbctypename] = CreoleTypes::DECIMAL; break; case SQL_NUMERIC: self::$typeMap[$odbctypename] = CreoleTypes::NUMERIC; break; case SQL_BIT: self::$typeMap[$odbctypename] = CreoleTypes::BOOLEAN; break; case SQL_TINYINT: self::$typeMap[$odbctypename] = CreoleTypes::TINYINT; break; case SQL_SMALLINT: self::$typeMap[$odbctypename] = CreoleTypes::SMALLINT; break; case SQL_INTEGER: self::$typeMap[$odbctypename] = CreoleTypes::INTEGER; break; case SQL_BIGINT: self::$typeMap[$odbctypename] = CreoleTypes::BIGINT; break; case SQL_REAL: self::$typeMap[$odbctypename] = CreoleTypes::REAL; break; case SQL_FLOAT: self::$typeMap[$odbctypename] = CreoleTypes::FLOAT; break; case SQL_DOUBLE: self::$typeMap[$odbctypename] = CreoleTypes::DOUBLE; break; case SQL_BINARY: self::$typeMap[$odbctypename] = CreoleTypes::BINARY; break; case SQL_VARBINARY: self::$typeMap[$odbctypename] = CreoleTypes::VARBINARY; break; case SQL_LONGVARBINARY: self::$typeMap[$odbctypename] = CreoleTypes::LONGVARBINARY; break; case SQL_DATE: self::$typeMap[$odbctypename] = CreoleTypes::DATE; break; case SQL_TIME: self::$typeMap[$odbctypename] = CreoleTypes::TIME; break; case SQL_TIMESTAMP: self::$typeMap[$odbctypename] = CreoleTypes::TIMESTAMP; break; case SQL_TYPE_DATE: self::$typeMap[$odbctypename] = CreoleTypes::DATE; break; case SQL_TYPE_TIME: self::$typeMap[$odbctypename] = CreoleTypes::TIME; break; case SQL_TYPE_TIMESTAMP: self::$typeMap[$odbctypename] = CreoleTypes::TIMESTAMP; break; default: self::$typeMap[$odbctypename] = CreoleTypes::OTHER; break; } } @odbc_free_result($result); }
<?php $dsn = "retstest"; $user = "******"; $pwd = "Schmoe"; // make a connection echo "about to make a make a connection<br/>"; $conn = odbc_connect($dsn, $user, $pwd); echo "connection made<br/>"; // query supported types echo "about to get primitive types supported<br/>"; $queryexec = odbc_gettypeinfo($conn); echo "post getTypeinfo<br/>"; // display results echo "about to display results<br/>"; odbc_result_all($queryexec, "BORDER=1"); // close a connection echo "about to close connection<br/>"; odbc_close($conn); echo "connection closed<br/>";