DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old August 17th, 2007, 07:10 AM
SimonJ621 SimonJ621 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 40 SimonJ621 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 50 m
Reputation Power: 3
Db2_columns difficulty

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 Code:
if ($con) {
   
   
$schema "%";
   
$tbl "table1";
   
   
$store db2_columns($con""$schema$tbl"");

   echo 
db2_result($store"COLUMN_NAME"); 


If I var_dump $store, I get the following:

Quote:
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/

Reply With Quote
  #2  
Old August 17th, 2007, 09:36 AM
SimonJ621 SimonJ621 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 40 SimonJ621 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 50 m
Reputation Power: 3
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 Code:
 $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();




Jason
-------------------------
http://www.elefoo.com/
http://www.blackspyraldancer.com/

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > Db2_columns difficulty


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway