467,200 Members | 1,008 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,200 developers. It's quick & easy.

Return columns using db2_columns() via PHP

SimonJ621
Hi,

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);
[PHP]
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.

Jason
---------------------------------------------------------
http://www.elefoo.com/
http://www.blackspyraldancer.com/
Aug 17 '07 #1
  • viewed: 1988
Share:
1 Reply
SimonJ621
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) {
$sql = "SELECT * FROM TABLE1 FETCH FIRST 1 ROWS ONLY";
$stmt = db2_prepare($dbconn, $sql);
$db2_execute($stmt);

$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);
$i++;
}
else {
echo "Connection failed.<br />";
echo db2_conn_errormsg();
}[/PHP]


Jason
-------------------------
http://www.elefoo.com/
http://www.blackspyraldancer.com/
Aug 17 '07 #2

Post your reply

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

Similar topics

2 posts views Thread by Nuno Barros | last post: by
3 posts views Thread by Hoodworld | last post: by
5 posts views Thread by D. Shane Fowlkes | last post: by
4 posts views Thread by Rob | last post: by
2 posts views Thread by Hrvoje Voda | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.