473,320 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

db2_columns trouble

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
2 1259
Atli
5,058 Expert 4TB
Hi.

Try putting '%' as a column name, instead of an empty string.
Aug 17 '07 #2
I attempted to change the column name, but the result was the same. Thank you for the suggestion.

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 #3

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

Similar topics

6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
1
SimonJ621
by: SimonJ621 | last post by:
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...
2
by: JLupear | last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post? I split it...
0
by: mrchatgroup | last post by:
news from http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html Small Accidents Mean Big Trouble for Supercollider Image Scientists expect startup...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.