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>"; 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. > 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 > > > 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 Ah, how's the wind today? :-) -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA "I was removed from office," said Tom disappointedly. -- 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]