You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by E B <hi...@yahoo.com> on 2001/05/18 14:41:18 UTC

escape '

Hi

I have a problem which I am sure there is an easy
solution to but I just can't find it.

I use DBI and when I write to MySQL a string
containing ' (for example the word can't) I get this
error.

[6631]ERR: 32: Line 157: Warning in Perl code:
DBD::mysql::st execute failed: You have an error in
your SQL syntax near 't' WHERE id='5'' at line 1 at
skrifagrunn.epl line 160.

I need to escape ' but no matter how I try it does not
work.

John Gustavson



__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: escape '

Posted by Kee Hinckley <na...@somewhere.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 5:41 AM -0700 5/18/01, E B wrote:
>Hi
>
>I have a problem which I am sure there is an easy
>solution to but I just can't find it.
>
>I use DBI and when I write to MySQL a string
>containing ' (for example the word can't) I get this
>error.

As someone suggested, you can use placeholders.  But you can also use 
the quote() method on DBI to quote any arguments before you pass them 
in.

Note that if these arguments are coming from a user, some type of 
quoting is critical or you are going to open yourself up to security 
problems.

You also may want to checkout DBIx::Recordset.  You'll lose a little 
in efficiency, but gain a lot in easy of use (including automatic 
quoting).
- -- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBOwVokCZsPfdw+r2CEQIZzACgodOrG6bWf4/Z38BK/vobrvjZX+oAoJIi
GlvM7B/Qg5PQks+Wzb1y1pMz
=+hNj
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: escape '

Posted by barries <ba...@slaysys.com>.
On Fri, May 18, 2001 at 01:56:29PM -0400, Ilia Lobsanov wrote:
> the SQL way to escape ' is to use ''.
> The preferred DBI way to escape things is to always use placeholders.
> See perldoc DBI... or checkout DBIx::AbstractLite as an easier DBI alternative ala $DB->query('SELECT * FROM foo WHERE bar = ?', $bar);

Also see the quote() function on the DBI documentation.

- Barrie

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: escape '

Posted by Ilia Lobsanov <il...@lobsanov.com>.
the SQL way to escape ' is to use ''.
The preferred DBI way to escape things is to always use placeholders.
See perldoc DBI... or checkout DBIx::AbstractLite as an easier DBI alternative ala $DB->query('SELECT * FROM foo WHERE bar = ?', $bar);

ilia.

On Fri, May 18, 2001 at 05:41:18AM -0700, E B wrote:
> Hi
> 
> I have a problem which I am sure there is an easy
> solution to but I just can't find it.
> 
> I use DBI and when I write to MySQL a string
> containing ' (for example the word can't) I get this
> error.
> 
> [6631]ERR: 32: Line 157: Warning in Perl code:
> DBD::mysql::st execute failed: You have an error in
> your SQL syntax near 't' WHERE id='5'' at line 1 at
> skrifagrunn.epl line 160.
> 
> I need to escape ' but no matter how I try it does not
> work.
> 
> John Gustavson
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org