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
odbc_data_source
(PHP 4 >= 4.3.0, PHP 5)
odbc_data_source — Devuelve información sobre una conexión actual
Descripción
array odbc_data_source
( resource $connection_id
, int $fetch_type
)
Esta función devolverá la lista de DSN disponibles (después de llamarla varias veces).
Parámetros
- connection_id
-
El conector identificador ODBC, ver odbc_connect() para más información.
- fetch_type
-
El parámetro fetch_type puede ser uno de los dos tipos de constantes: SQL_FETCH_FIRST, SQL_FETCH_NEXT. Use SQL_FETCH_FIRST la primera vez que llame a esta función, a partir de entonces use SQL_FETCH_NEXT.
Valores devueltos
Devuelve FALSE si se produjo un error, y un array si tuvo éxito.
critmas at hotmail dot com
25-Feb-2005 07:53
angelo [at] spaceblue [dot] com
01-Dec-2003 06: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);
