faqts : Computers : Programming : Languages : PHP : Database Backed Sites : Interbase

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 29 people (66%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

odbc_columns, odbc_tables in interbase via ODBC: example

Sep 26th, 2002 12:41
Jeff Stern,


using odbc_columns() with interbase can be wierd. odbc_columns (as of 
9/26/2002) is not well documented 
(http://www.php.net/manual/en/function.odbc-columns.php), and also with 
interbase, it is not clear what to use for a "TABLE_QUALIFIER" 
(aka "TABLE_CAT") or a "TABLE_SCHEMA" in an interbase context..
it turns out that on the default ib6 system, these are null/blank 
anyway, but how to address this in the odbc_columns() call?
by playing around with odbc_tables and odbc_results_all() i figured out 
which parameters will work (at least for me).. your mileage may vary.. 
but hopefully this will get you into the ballpark.
i provide here 2 php pages. one to list all the tables (tables.php) in 
your odbc database, and the other (columns.php) to list all the columns 
in each of the tables you click on in your first page.
i am assuming you use the odbc functions to access your interbase 
server, and you have a label (aka 'DSN') set up for this 
database/user/passwd combo in your /etc/odbc.ini file, something like 
the below (where 'ib6' is your 'DSN'):
=====/etc/odbc.ini================================================
[ib6]
Driver              = INTERBASE
Description = interbase driver
Database    = localhost:/opt/interbase/examples/employee.gdb
User        = sysdba
Password    = masterkey
With_Schema = 0
Dialect     = 3
Charset     =
Role        =
Nowait      = 0
==================================================================
notice you don't have to fill in the username and password in the 
odbc_connect() function (we just use ""'s, there), because these are 
already supplied in your odbc.ini file (i never understood why there 
isn't a single-parameter odbc_connect() call, like 'odbc_connect
("ib6")'.., oh, well). change your database DNS from 'ib6' to whatever 
you have, if you have something else..
=====tables.php===================================================
<?
$connection = odbc_connect("ib6", "", "") or die(odbc_error_msg());
$tables = @odbc_tables($connection) or die(odbc_error_msg());
$table_list = "<ul>
";
$i = 0;
while (odbc_fetch_row($tables)) {
  if (odbc_result($tables, 4) == "TABLE")
  $table_list .= "<li><a href=\"columns.php?table_name=" . odbc_result
($tables, 
3) . "\">" . odbc_result($tables, 3) . "</a>
";
}
$table_list .= "</ul>
";
?>
<html>
<head>
<title>Tables</title>
</head>
<body>
<p><strong>Tables</strong>
</p>
<? echo "$table_list"; ?>
</body>
</html>
=====columns.php==================================================
<html>
<head>
<title>Columns of table "<? echo "$table_name"; ?>"</title>
</head>
<body>
<p><strong>Columns of table "<? echo "$table_name"; ?>":</strong>
</p>
<p>
<?
$conn = odbc_connect("db1", "", "") or die(odbc_error_msg());
$table_name = $_GET[table_name];
$cols = odbc_columns($conn, "%", "", $table_name ) or die(odbc_error_msg
());
$function_result = odbc_result_all($cols);
echo "function result = " . $function_result;
?>
</p>
</body>
</html>
==================================================================
hope this helps someone..