PHP Doku:: Returns information about a current connection - function.odbc-data-source.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAbstraktionsebenenODBC (Unified)ODBC Funktionenodbc_data_source

Ein Service von Reinhard Neidl - Webprogrammierung.

ODBC Funktionen

<<odbc_cursor

odbc_do>>

odbc_data_source

(PHP 4 >= 4.3.0, PHP 5)

odbc_data_sourceReturns information about a current connection

Beschreibung

array odbc_data_source ( resource $connection_id , int $fetch_type )

This function will return the list of available DSN (after calling it several times).

Parameter-Liste

connection_id

Eine ODBC-Verbindungsressource, siehe odbc_connect() für Details.

fetch_type

The fetch_type can be one of two constant types: SQL_FETCH_FIRST, SQL_FETCH_NEXT. Use SQL_FETCH_FIRST the first time this function is called, thereafter use the SQL_FETCH_NEXT.

Rückgabewerte

Returns FALSE on error, and an array upon success.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
critmas at hotmail dot com
25.02.2005 20:53
Thank you Angelo for point out the code.  Though the function doesn't really do what it is supposed to.  It returns the entire list of ODBC DSNs.
If you really are looking to get the server type based on just the ODBC, username and password in an environment where the application needs to be aware of different types of databases, use the following code:

$link2 = odbc_connect($dsn , $DBUser, $DBPwd ) or die(odbc_errormsg() );
$result = @odbc_data_source( $link2, SQL_FETCH_FIRST );
while($result)
{
    if (strtolower($dsn) == strtolower($result['server'])) {
        echo $result['description'] . "<br>\n";
        break;
    }
       else
        $result = @odbc_data_source( $link2, SQL_FETCH_NEXT );
}

odbc_close($link2);

// Hope it saves your precious time
angelo [at] spaceblue [dot] com
1.12.2003 19:51
// Example usage:

// Connect to a ODBC database that exists on your system
$link = odbc_connect("some_dsn_name", "user", "password") or die(odbc_errormsg() );

$result = @odbc_data_source( $link, SQL_FETCH_FIRST );
while($result)
{
    echo "DSN: " . $result['server'] . " - " . $result['description'] . "<br>\n";
    $result = @odbc_data_source( $link, SQL_FETCH_NEXT );
}

odbc_close($link);



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)