Re: PHP datatype vs Oracle Varchar2
| From: | Thies C. Arntzen | Date: | Fri, 27 Jul 2001 18:08:41 +0000 |
| Subject: | Re: PHP datatype vs Oracle Varchar2 | ||
| References: | 1 2 | Groups: | php.install |
| Request: | Send a blank email to php-install+get-3733@lists.php.net to get a copy of this message | ||
On Thu, Jul 26, 2001 at 07:27:07PM -0500, Victoria Zhou wrote:
> Here is a description of the testcase for the problem:
>
> Oracle:
> Create table Mytable (
> Username varchar2(20),
> Passwd varchar2(20),
> Usertype varchar2(50))
>
> Insert into Mytable (Username, Passwd, Usertype)
> values('tester1','tester1','Operator');
>
> PHP:
> $sql = "select * from Mytable where Username='tester1'";
> $sql_statement = OCIParse($conn, $sql) or die ("Couldn't parse statement");
> OCIExecute($sql_statement) or die ("Couldn't execute query");
>
>
> Problem:
> The string comaparison in the $sql (Username='tester1') is never true,
> because Username is a variable length string and 'tester1' is considered as
> a fixed length string.
wrong - that should not be the case.
>
> I don't have the flexibility to change VARCHAR2 to CHAR in order to make
> this work, because a fixed length string will cause a lot of trouble for
> string comparisons for other code in the program.
>
> Thanks for your help!
i did the same thing (i hope) and it woorsk for me. i see no
reason why it shouldn't work. there is _no_ reason to switch
to from varchar to char!
please try to do the _same_ select-statement in sqlplus -
tc
>
> Victoria
>
>
>
>
> > -----Original Message-----
> > From: Thies C. Arntzen [mailto:thies@thieso.net]
> > Sent: Thursday, July 26, 2001 6:10 PM
> > To: Victoria Zhou
> > Cc: php-install@lists.php.net; php_install@lists.php.net
> > Subject: Re: [PHP-INST] PHP datatype vs Oracle Varchar2
> >
> >
> > On Thu, Jul 26, 2001 at 05:08:42PM -0500, Victoria Zhou wrote:
> > >
> > > Hi,
> > >
> > > The comparison between Oracle VARCHAR2 and a PHP string doesn't seems to
> > > work. Detail as follows:
> > >
> > > I have one PHP variable and one Oracle column:
> > > . $form_user_id: a PHP string obtained from web form input,
> > such as 'user1'.
> > > . Username: an oracle table column of type VARCHAR2(20).
> > >
> > > The following sql statement failed:
> > > "select * from mytable where Username='$form_user_id'"
> > >
> > > It failed because Username has a strlen of 20, where $form_user_id has a
> > > strlen of 5. If I changed the Username from VARCHAR2(20) to
> > CHAR(20), then
> > > this sql worked fine. But I think with Oracle VARCHAR2, the strlen of
> > > Username in this case should be 5 instead of 20.
> >
> > you must be doing something wrong here;-)
> >
> > please try to create a _tiny_ testcase (< 20 lines) and post
> > it to the list, i'm sure you're overseeing something
> > important.
> >
> > tc
> >
> >
>