PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

odbc_commit> <odbc_columnprivileges
Last updated: Fri, 10 Oct 2008

view this page in

odbc_columns

(PHP 4, PHP 5)

odbc_columns指定したテーブルにあるカラム名のリストを取得する

説明

resource odbc_columns ( resource $connection_id [, string $qualifier [, string $schema [, string $table_name [, string $column_name ]]]] )

指定したテーブルにあるカラム名のリストを取得します。

パラメータ

connection_id

ODBC 接続 ID。詳細は odbc_connect() を参照ください。

qualifier

修飾子。

schema

所有者。

table_name

テーブル名。

column_name

カラム名。

schema , table_name および column_name には検索パターン (ゼロ以上の文字にマッチする '%' や単一の文字にマッチする '_') を使用可能です。

返り値

ODBC 結果 ID または失敗した場合に FALSE を返します。

結果セットは以下のカラムを有しています。

  • TABLE_QUALIFIER
  • TABLE_SCHEM
  • TABLE_NAME
  • COLUMN_NAME
  • DATA_TYPE
  • TYPE_NAME
  • PRECISION
  • LENGTH
  • SCALE
  • RADIX
  • NULLABLE
  • REMARKS

結果セットは TABLE_QUALIFIER、TABLE_SCHEM、TABLE_NAME でソートされます。

参考



odbc_commit> <odbc_columnprivileges
Last updated: Fri, 10 Oct 2008
 
add a note add a note User Contributed Notes
odbc_columns
php dot lpatrick at spamgourmet dot com
02-May-2008 10:52
Since I was just looking for table descriptions of an MS Access file I didn't know the table structure of, I wrote this (where $inputfile is the Access file name):

<?php
$conn
= odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".$inputfile;, "", "");

$tabs = odbc_tables($conn);
$tables = array();
while (
odbc_fetch_row($tabs)){
    if (
odbc_result($tabs,"TABLE_TYPE")=="TABLE") {
       
$table_name = odbc_result($tabs,"TABLE_NAME");
       
$tables["{$table_name}"] = array();
       
$cols = odbc_exec($conn,'select * from `'.$table_name.'` where 1=2');  // we don't want content
     
$ncols = odbc_num_fields($cols);
        for (
$n=1; $n<=$ncols; $n++) {
           
$field_name = odbc_field_name($cols, $n);
           
$tables["{$table_name}"]["{$field_name}"]['len'] = odbc_field_len($cols, $n);
           
$tables["{$table_name}"]["{$field_name}"]['type'] = odbc_field_type($cols, $n);
        }
    }
}
odbc_close ($conn);
print_r($tables);
?>
jeremie dot legrand at komori-chambon dot fr
19-Feb-2008 02:43
Here is the way to use odbc_columns() with "Attunity Connect", an ODBC connector to VMS :

$db = "my_database";
$table = "my_table";
$con = odbc_connect($db, "user", "password");
$result = odbc_columns($con, $db, "", $table, "%");
while (odbc_fetch_row($resu)) {
    echo odbc_result_all($resu);
}
Artur
23-Jan-2007 06:15
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 at comcast dot net
26-Nov-2004 05:47
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);
laundro at gmail dot com
15-Nov-2004 08:29
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 at hotamil dot com
25-Feb-2004 02:21
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("<p><font color=#FF0000>Erro Na Leitura da Tabela ".$tabela." do AS/400: ".odbc_errormsg());

echo odbc_result_all($res400);

Netaminas.com
PORTUGAL
21-Oct-2003 11:44
ODBC & MS ACCESS :

odbc_columns($conn,"DSN_NAME","","TABLE_NAME");
Sergio Sartori
25-Feb-2003 08:05
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.
jastern at uci dot edu
26-Sep-2002 02:34
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
josh at engledental dot com
12-Jun-2002 05:34
(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.
LyleE at LocalMotion dot com
22-Feb-2001 11:53
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.

odbc_commit> <odbc_columnprivileges
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites