note 82933 added to function.odbc-columns

From: Date: Fri, 02 May 2008 17:52:02 +0000
Subject: note 82933 added to function.odbc-columns
Groups: php.notes 
Request: Send a blank email to php-notes+get-138998@lists.php.net to get a copy of this message
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); ?> ---- Server IP: 193.190.67.10 Probable Submitter: 81.11.199.247 ---- Manual Page -- http://www.php.net/manual/en/function.odbc-columns.php Edit -- https://master.php.net/note/edit/82933 Del: integrated -- https://master.php.net/note/delete/82933/integrated Del: useless -- https://master.php.net/note/delete/82933/useless Del: bad code -- https://master.php.net/note/delete/82933/bad+code Del: spam -- https://master.php.net/note/delete/82933/spam Del: non-english -- https://master.php.net/note/delete/82933/non-english Del: in docs -- https://master.php.net/note/delete/82933/in+docs Del: other reasons-- https://master.php.net/note/delete/82933 Reject -- https://master.php.net/note/reject/82933 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138998) next »