Re: DB wildcards

From: Date: Sat, 14 May 2005 14:55:10 +0000
Subject: Re: DB wildcards
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19216@lists.php.net to get a copy of this message
Danny Brow wrote:
I can't seem to get wild cards (?) to work right, the below code returns nothing from the database. But if I change the first ? to last_name like: [snip]
$last_name = 'Brow'; $field = 'last_name'; $q = $db->getAll('SELECT * FROM patients WHERE ? LIKE ?',
                    array($field, $last_name));
This will translate into: $db->getAll("SELECT * FROM patients WHERE 'last_name' LIKE 'Brow'"); If you're grabbing $field from external input, the system you're using is dangerous - I would recommend being much stricter: if (in_array(strtolower($_POST['field']), array('last_name', 'first_name', // other fields )) { $field = strtolower($_POST['field']); } else { returnError(); } Greg

« previous php.pear.general (#19216) next »