By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,924 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,924 IT Pros & Developers. It's quick & easy.

Return columns using db2_columns() via PHP

P: 12

I am attempting to retrieve column names from a table in DB2 using php. While I have a valid connection to the database, I cannot get the db2_columns function to return results. I'm very new to using DB2 and would appreciate any help or suggestions. The following is the code I am attempting:

$con = db2_pconnect($dbname, $username, $password);
if ($con) {

$schema = "%";
$tbl = "table1";

$store = db2_columns($con, "", $schema, $tbl, "");

echo db2_result($store, "COLUMN_NAME");[/PHP]

If I var_dump $store, I get the following:

resource(3) of type (DB2 Statement) bool(false)
I know the connection works because I have been able to run sql and return results using the same connection. Thank you for all your help.

Aug 17 '07 #1
Share this Question
Share on Google+
1 Reply

P: 12
Well, I didn't figure out how to use db2_columns correctly, but I'm under a time constraint so the following is my work-around to grab the number of columns and the column names:

[PHP]$dbconn = db2_pconnect($dbname, $username, $password);

if ($dbconn) {
$stmt = db2_prepare($dbconn, $sql);

$colNumber = 0;

while ($result = db2_fetch_array($stmt)) {
$colNumber = count($result);

$i = 0;
$colNames = array();

while ($i < $colNumber) {
$colNames[$i] = db2_field_name($stmt, $i);
else {
echo "Connection failed.<br />";
echo db2_conn_errormsg();

Aug 17 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.