db2_columns trouble

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SimonJ621
    New Member
    • Aug 2007
    • 12

    db2_columns trouble

    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($d bname, $username, $password);
    [PHP]
    if ($con) {

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

    $store = db2_columns($co n, "", $schema, $tbl, "");

    echo db2_result($sto re, "COLUMN_NAM E");[/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.blackspyral dancer.com/
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Try putting '%' as a column name, instead of an empty string.

    Comment

    • SimonJ621
      New Member
      • Aug 2007
      • 12

      #3
      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($d bname, $username, $password);

      if ($dbconn) {
      $sql = "SELECT * FROM TABLE1 FETCH FIRST 1 ROWS ONLY";
      $stmt = db2_prepare($db conn, $sql);
      $db2_execute($s tmt);

      $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_errorm sg();
      }[/PHP]


      Jason
      -------------------------
      http://www.elefoo.com/
      http://www.blackspyral dancer.com/

      Comment

      Working...