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



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

odbc_columns

Lists the column names in specified tables (PHP 4, PHP 5)
resource odbc_columns ( resource connection_id [, string qualifier [, string schema [, string table_name [, string column_name]]]] )

Examples ( Source code ) » odbc_columns

<?
$conn 
odbc_connect("db1""""") or die(odbc_error_msg());

$cols odbc_columns($conn"%""""table_name" ) or die(odbc_error_msg());
$function_result odbc_result_all($cols);
echo 
"function result = " $function_result;
?>

Code Examples / Notes » odbc_columns

sergio sartori

Using this function on a MS SQL Server 2000 database connection with the syntax:
$res = odbc_columns($connId, $dbName, "%", $tableName, "%");
I actually get a result set with THESE columns name:
TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_SIZE, BUFFER_LENGTH, DECIMAL_DIGITS, NUM_PREC_RADIX, NULLABLE, REMARKS
in the order displayed.


lylee

Took me a while to figure out this command, thought I would save some other people the time.  We couldn't quite figure out what the qualifier was.  For MSSQL 7.0, it is the Database that you are connecing to.  For the pubs database it would look something like this.
$rs = odbc_columns($DBConnection, "Pubs", "%", "jobs");
That would be for showing the jobs table.


artur

This is the only way I could actually get field names using odbc_columns. Hope it will be usefull for someone.
$result = odbc_columns($odbc,$dbhost,"dbo", "KIR_ViolationDetail");
while (odbc_fetch_row($result))
{
 echo odbc_result($result,"COLUMN_NAME");
}


ke3wh

The complete script to get into from a DSN MS Access DB Table and display it is below.
function Error_Handler( $msg, $cnx ) {
   echo "$msg \n";
   odbc_close( $cnx);
   exit();
   }
$cnx = odbc_connect( 'DSN_NAME' , '', '' );//connect to MSAccess
   if (!$cnx) {
     Error_handler( "Error in odbc_connect" , $cnx );
   }  
   $res400= odbc_columns($cnx,"DSN_NAME","","TABLE");
   echo odbc_result_all($res400);


21-oct-2003 07:44

ODBC & MS ACCESS :
odbc_columns($conn,"DSN_NAME","","TABLE_NAME");


jastern

i put an example of using odbc_columns() and odbc_tables() with interbase/ODBC at:
http://www.faqts.com/knowledge_base/view.phtml/aid/18988


laundro

Getting all column names from Excel with ODBC:
$cols = odbc_columns($connection, $filename, NULL, $sheet);
where:
$connection is the result of your odbc_connect;
$filename is the filename of the Excel file;
$sheet is the name of the Excel worksheet.
This is useful when you want to query an Excel file without having to name ranges beforehand. With the results obtained from the above command, you can populate an array and use its contents (ie the column names) for further querying.


netaminas

Connect with IBM Client Access 32-bit ODBC driver
To access table information in DB2 iSeries (AS/400) via ODBC Driver i've tried with this code and worked!!!
$conn_ODBC = odbc_connect("DSN", "USER", "PASSW") or die;
$tabela = "table name in IBM iSeries";
$libname = "library name in IBM iSeries"
$res400 = odbc_columns($conn_ODBC, "DSN", $libname, $tabela, "%")  or die("

<font color=#FF0000>Erro Na Leitura da Tabela ".$tabela." do AS/400: ".odbc_errormsg());
echo odbc_result_all($res400);
Netaminas.com
PORTUGAL


fmk

Before PHP 4.0.3 uou could use this function with 1 or 5 prarms. From 4.0.3 the function matches the documentation.

josh

(PHP4.2.1, Win2k, MSSQL 2K)
The result id returned from this function does not appear to behave exactly the same as a result id returned from a query.  
I get all sorts of errors when I try to use subsequent odbc functions on the result id, such as:
odbc_fetch_into - This function only seems to work if I don't specify a row number or if the row number = 0.
odbc_fetch_row - This function will not return a row from the result set.  Under some scenarios, I am able to use it in a while loop, but its seems buggy.  Hence, my odbc_num_of_rows function (hack to replace the non-functional odbc_num_rows function) also doesn't work.
I recommend dumping the results into an array immediately and freeing the result id created by this function.
ps - If anyone has any further insight or workarounds, I would appreciate them.


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