Re: Escaping metacharacters - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Escaping metacharacters
Date
Msg-id 87y8lgsokr.fsf@stark.xeocode.com
Whole thread Raw
In response to Escaping metacharacters  (DarkSamurai <julio@invlaid.linux.net>)
List pgsql-hackers
DarkSamurai <julio@invlaid.linux.net> writes:

> And suppose I use this :
> 
> > $cat = $GET["category"];
> > $query = " SELECT Id, Title, Abstract FROM News " . "Where Category=" . $cat;

From a security point of view you're even better off using something like

$dbh->query("SELECT id, title, abstract FROM news WHERE category = ?", $cat);

Or whatever the equivalent syntax is in your driver. Avoiding mixing
user-provided data with the code entirely. The driver may still have to do the
mixing but it's probably better at it than you are. And in newer versions of
Postgres it doesn't even have to do it at all, and can ship the data to the
server separately.

-- 
greg



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Toward better documentation
Next
From: Bruce Momjian
Date:
Subject: CVS compile failure