Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: SV: making sql queries safe


Message #1 by "Datatal AB - Gauffin, Jonas" <jonas@d...> on Tue, 17 Dec 2002 16:03:32 +0100
> No need to escape strings if magic_qoutes is enabled.
> If not, just use addslashes, stripslashes.
> For mysql use mysql_escape.
> 

I'm trying to create a generic function that you 
can pass an _entire_ query (as one string) into.
(That works no matter quotes on or off)

Example query..

	insert into user ('john's', 'password')

If you add slashes, as you suggest, you would get..

	insert into user (\'john\'s\', \'password\')

But what it needs to be is..

	insert into user ('john\'s', 'password')

I know that you can addslashes to the _individual_ 
values as you are _building_ the query... I am trying 
to work with the 'built' query as a whole. 

Hence the use of regular expressions..

Try the sample code I submitted and you will see 
what I mean.

Cheers,
Justin :)

  Return to Index