RE: [PHP-DB] odbc query with single quote in string
| From: | Squirrel User | Date: | Wed, 05 Feb 2003 19:20:46 +0000 |
| Subject: | RE: [PHP-DB] odbc query with single quote in string | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25458@lists.php.net to get a copy of this message | ||
The 1st one didn't work, but the 2nd one did work. Fantastic! Thanks alot,
you saved me from frustrations.
Quoting "John W. Holmes" <holmes072000@charter.net>:
> > I'm having problem querying a table with a field value containing an
> > appostropy, please help. Using ODBC to connect MSAcess database.
> >
> > $mQuery = "CustomerID='$mCust'";
> > $mCur2 = odbc_do( $mCnx, "select Login from Emails where $mQuery"
> );
> >
> > When it hits "O'Donald, James", I get error in odbc_exec(). I tried
> > variations of $mQuery, including:
> >
> > $mQuery = addslashes( $mQuery );
>
> You don't want to use addslashes() on $mQuery, you want to use it on the
> data you're inserting between the quotes, i.e. $mCust.
>
> $mQuery = "CustomerID='" . addslashes($mCust) . "'";
>
> If that still causes an error, your database may require quotes to be
> escaped with another quote, instead of a backslash. In that case, you
> can create a function like this
>
> function addslashes2($data)
> { return str_replace("'","''",$data); }
>
> Hope that helps.
>
> ---John W. Holmes...
>
> PHP Architect - A monthly magazine for PHP Professionals. Get your copy
> today. http://www.phparch.com/
>
>
>
-------------------------------------------------
This mail sent through ISOT. To find out more
about ISOT, visit http://isot.com