php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14851 problems w/ db2 char() for bit data
Submitted: 2002-01-04 12:13 UTC Modified: 2002-06-02 20:06 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: jfreed at fbsdata dot com Assigned:
Status: Closed Package: ODBC related
PHP Version: 4.1.1 OS: Redhat-6.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jfreed at fbsdata dot com
New email:
PHP Version: OS:

 

 [2002-01-04 12:13 UTC] jfreed at fbsdata dot com
I configured php-4.1.1 as follows:

./configure --with-mysql=usr --with-apache=/usr/local/apache/src/apache_1.3.22 --with-ibm-db2=/home/flexadm/sqllib --enable-track-vars

It seems to work okay, but all of the keys in our database are defined as TECH_ID CHAR(13) FOR BIT DATA NOT NULL.  This is then automatically generated with the GENERATE_UNIQUE() function of DB2.

PHP appears to have problems working with this type of data.  As the following code has problems on my system:

<?php

   $con = odbc_pconnect("database", "username", "password")
          or
          die("odbc_pconnect() failed.<br>\n");

   $rs = odbc_exec($con, "SELECT TECH_ID FROM LOGON WHERE LOGIN_NAME = 'sbr'");

   if(odbc_fetch_row($rs))
      $tech_id = odbc_result($rs, "tech_id");
   else
      die("Could not find tech_id<br>\n");

   $rs = odbc_exec($con, "SELECT LOGIN_NAME FROM LOGON WHERE TECH_ID = ".$tech_id);
   if(odbc_fetch_row($rs))
      $login = odbc_result($rs, "login_name");
   else
      $login = "UNKNOWN";

   echo "TECH_ID: ".$tech_id."<br>\n";
   echo "LOGIN: ".$login."<br>\n";
?>


The above code yields the following results in the browser:

Warning: SQL error: [IBM][CLI Driver][DB2/SUN] SQL0007N The character " " following "OGON WHERE TECH_ID =" is not valid. SQLSTATE=42601 , SQL state 42601 in SQLExecDirect in /home/jfreed/public_html/debug.php on line 13

Warning: Supplied argument is not a valid ODBC result resource in /home/jfreed/public_html/debug.php on line 14
TECH_ID: 'EbR
LOGIN: UNKNOWN

This lead me to try the odbc_binmode() function.  So I added the following line to my code (right under the initial odbc_exec() call:

odbc_binmode($rs, ODBC_BINMODE_CONVERT);


Now the output is as follows:

Warning: SQL error: [IBM][CLI Driver][DB2/SUN] SQL0401N The data types of the operands for the operation "=" are not compatible. SQLSTATE=42818 , SQL state 42818 in SQLExecDirect in /home/jfreed/public_html/debug.php on line 15

Warning: Supplied argument is not a valid ODBC result resource in /home/jfreed/public_html/debug.php on line 16
TECH_ID: 20010504142745046252
LOGIN: UNKNOWN



Now, when I'm using the DB2 CLI to do this kind of stuff, I get the tech_id as:

x'2001050412745046252000000'

This leads me to believe that we're on the right track here, just that perhaps PHP is not translating this binary data quite properly.

Please let me know if you have any advice.  I would be very grateful to find a way around this problem as my company would require this to work in order to move from CGI to PHP.

Thanks for your time.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-02 20:06 UTC] kalowsky@php.net
Please read your error message carefully and look at the work you've done.

> $rs = odbc_exec($con, "SELECT LOGIN_NAME FROM LOGON WHERE 
> TECH_ID = ".$tech_id);

> It seems to work okay, but all of the keys in our database 
> are definedas TECH_ID CHAR(13) FOR BIT DATA NOT NULL.

My first suggestion is to say that your SELECT is wrong.  If you're using a char, you need to place that information within single quotes to be marked.  
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 17:01:29 2024 UTC