> On Tue, 23 Oct 2001 16:35, Grant Walters wrote:
> > I'm going nuts trying to work out how to handle errors from data
> > statement with single quotes.  PHP 4.0.6 appears to be mangling
> > something somewhere.
> > All statements work with the Openlink odbctest program
> > Any help appreciated
> >
> > <?
> > $conn = odbc_connect("$dsn","","","$cursor");
> > $sql="SELECT ID,Category,description FROM card_type WHERE
> > description='IMPEYS'"; echo "<BR><b>SQL:</b> $sql<BR>";
> > $results = odbc_do($conn,$sql);
> > if ($results) {
> >   while (odbc_fetch_into($results,$row)) {
> >     echo $row[0]." ".$row[1]." ".$row[2]."\n";
> >   }
> > }
> > $sql="SELECT ID,Category,description FROM card_type WHERE description
> > LIKE '%PEP%'"; echo "<BR><b>SQL:</b> $sql<BR>";
> > $results = odbc_do($conn,$sql);
> > if ($results) {
> >   while (odbc_fetch_into($results,$row)) {
> >     echo $row[0]." ".$row[1]." ".$row[2]."\n";
> >   }
> > }
> > $sql='SELECT ID,Category,description FROM card_type WHERE description
> > LIKE "%PEP%"'; echo "<BR><b>SQL:</b> $sql<BR>";
> > $results = odbc_do($conn,$sql);
> > if ($results) {
> >   while (odbc_fetch_into($results,$row)) {
> >     echo $row[0]." ".$row[1]." ".$row[2]."\n";
> >   }
> > }
> > $sql='SELECT ID,Category,description FROM card_type WHERE
> > description="PEPPERELL\'S"'; echo "<BR><b>SQL:</b> $sql<BR>";
> > $results = odbc_do($conn,$sql);
> > if ($results) {
> >   while (odbc_fetch_into($results,$row)) {
> >     echo $row[0]." ".$row[1]." ".$row[2]."\n";
> >   }
> > }
> > $sql="SELECT ID,Category,description FROM card_type WHERE
> > description=\"PEPPERELL'S\""; echo "<BR><b>SQL:</b> $sql<BR>";
> > $results = odbc_do($conn,$sql);
> > if ($results) {
> >   while (odbc_fetch_into($results,$row)) {
> >     echo $row[0]." ".$row[1]." ".$row[2]."\n";
> >   }
> > }
> > ?>
>
> If I were doing that with mysql, I would use
>  $sql="SELECT ID,Category,description FROM card_type WHERE
>  description='PEPPERELL\'S'; echo "<BR><b>SQL:</b> $sql<BR>";

I do the same for MySQL.  Appears there is a bug somewher in the PHP odbc code.  The 
Openlink team suggested using odbc_prepare
instead, and that works fine, so I'll be converting all of my classes to use 
odbc_prepare statements instead of odbc_do.  I've just
logged this as a bug on the php bug site, so we'll see if they can shed any further 
light on it.

> Given that you are probably getting the description value passed in, you
> might want to check your magic_quotes settings, and also perhaps echo the
> incoming value for description to see whether it is as you expect.
>
> You might have to play around with addslashes to get the right result.

Seems, that addslashes and magic_quotes have no impact at all.  I've downloaded and 
checked the M$ ODBC SDK and the error 37000 is
now error 42000 under ODBC 3.5?  It means that there is a syntax error in the SQL 
command being passed.  considering that everything
works fine from the odbctest program provided by Openlink and also works with 
odbc_prepare using ? and parameters, it must be in the
PHP stuff somewhere.

>
> > OUTPUT
>
> >
> > SQL: SELECT ID,Category,description FROM card_type WHERE
> > description="PEPPERELL'S" Warning: SQL error:
> > [OpenLink][ODBC][Driver]Syntax error or access, SQL state 37000 in
> > SQLExecDirect in /usr/local/.WWW/WEBS/_odbc/test.php3 on line 58
> >
> Ah, how's the wind today? :-)

Ever present.  I live right on the coast facing West, so it gets a wee bit 
rambunctious sometimes :-)


Regards

Grant Walters
Brainbench 'Most Valuable Professional' for Unix Admin
Walters & Associates, P O Box 13-043 Johnsonville, Wellington, NEW ZEALAND
Telephone: +64 4 4765175, CellPhone 025488265, ICQ# 23511989


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to