Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : ODBC Functions (Unified) : odbc_data_source

odbc_data_source

Returns information about a current connection (PHP 4 >= 4.3.0, PHP 5)
array odbc_data_source ( resource connection_id, int fetch_type )

Examples ( Source code ) » odbc_data_source

<?php

Example usage  odbc_data_source:
// 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$linkSQL_FETCH_FIRST );
while(
$result)
{
echo 
"DSN: " $result['server'] . " - " $result['description'] . "
\n"
;
$result = @odbc_data_source$linkSQL_FETCH_NEXT );
}
odbc_close($link);

?>

Code Examples / Notes » odbc_data_source

critmas

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'] . "
\n";
break;
}
  else
$result = @odbc_data_source( $link2, SQL_FETCH_NEXT );
}
odbc_close($link2);
// Hope it saves your precious time


angelo

// 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'] . "
\n";
$result = @odbc_data_source( $link, SQL_FETCH_NEXT );
}
odbc_close($link);


Change Language


Follow Navioo On Twitter
odbc_autocommit
odbc_binmode
odbc_close_all
odbc_close
odbc_columnprivileges
odbc_columns
odbc_commit
odbc_connect
odbc_cursor
odbc_data_source
odbc_do
odbc_error
odbc_errormsg
odbc_exec
odbc_execute
odbc_fetch_array
odbc_fetch_into
odbc_fetch_object
odbc_fetch_row
odbc_field_len
odbc_field_name
odbc_field_num
odbc_field_precision
odbc_field_scale
odbc_field_type
odbc_foreignkeys
odbc_free_result
odbc_gettypeinfo
odbc_longreadlen
odbc_next_result
odbc_num_fields
odbc_num_rows
odbc_pconnect
odbc_prepare
odbc_primarykeys
odbc_procedurecolumns
odbc_procedures
odbc_result_all
odbc_result
odbc_rollback
odbc_setoption
odbc_specialcolumns
odbc_statistics
odbc_tableprivileges
odbc_tables
eXTReMe Tracker