Select From Db2 W/php Error

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

    Select From Db2 W/php Error

    I am trying to select from a DB2 database with PHP. To my knowledge, the connection is being made, but the select statement won't run. The following is the error I receive:

    Warning: odbc_exec() [function.odbc-exec]: SQL error: [IBM][CLI Driver][DB2/AIX64] SQL0644N Invalid value specified for keyword "CONCURRENC Y" in statement "<ATTRIBUTE-STRING>". SQLSTATE=42615 , SQL state 42615 in SQLExecDirect in C:\wamp\www\db. php on line 24
    I can't find much help online, which is why I am posting here. Any help would be much appreciated as I have never attempted to use DB2. Following is my PHP code:

    [PHP]<?php

    function dbconnect($verb ose) {
    $dbname = "**";
    $username = "**";
    $password = "**";

    $dbconn = odbc_pconnect($ dbname, $username, $password);

    if (($verbose == TRUE) && ($dbconn == 0 )) {
    echo("connectio n to database failed.");
    $sqlerror = odbc_errormsg($ dbconn);
    echo "<br /><br />".$sqlerror."< br /><br />";
    }

    return($dbconn) ;
    }


    function display($dbconn ) {
    $select_stmt = "SELECT * FROM blabla";

    if ($dbconn != 0) {
    $result = odbc_exec($dbco nn, $select_stmt);
    if ($result == 0) {
    echo "SELECT statement failed.<br />";
    $sqlerror = odbc_errormsg($ dbconn);
    }
    else {
    odbc_result_all ($result);
    }
    }
    }

    $verbose = TRUE;
    $dbconn = dbconnect($verb ose);

    display($dbconn );


    ?>[/PHP]


    Thank you for all the help,

    Jason
    --------------------------
    http://www.elefoo.com/
    http://www.blackspyral dancer.com/
  • Purple
    Recognized Expert Contributor
    • May 2007
    • 404

    #2
    Hi Jason,

    What platform is the webserver running on ?

    Does the odbc datasource test ok ?

    Regards Purple

    Comment

    • SimonJ621
      New Member
      • Aug 2007
      • 12

      #3
      The datasource tests ok. I have the DB2 client on my Windows machine but the server itself runs on a UNIX box.

      Comment

      • SimonJ621
        New Member
        • Aug 2007
        • 12

        #4
        I used db2_connect instead of the odbc functions and it worked find. The following code worked:

        [PHP]$conn = db2_connect($db name, $username, $password);

        if ($conn) {
        $sql = "SELECT * FROM Table1";
        $stmt = db2_prepare($co n, $sql);
        db2_execute($st mt);

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

        while (db2_fetch_row( $stmt)) {
        $rows[$i] = db2_result($stm t, 0);
        echo $rows[$i]."<br />";
        $i++;
        }
        }
        else {
        echo "Connection failed. <br />";
        echo db2_conn_errorm sg();
        }[/PHP]

        Thanks again.

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

        Comment

        Working...