note 108093 deleted from function.mysql-query by tularis

From: Date: Tue, 26 Jun 2012 12:27:54 +0000
Subject: note 108093 deleted from function.mysql-query by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188811@lists.php.net to get a copy of this message
Note Submitter: ghighiaw at yahoo dot com ---- In dynamic queries using a variable in the query before defining it will result in the query run with wrong results: consider: $query = "SELECT emp_no FROM employees WHERE dpt_no = '$var'"; $var= 'dpt_it'; this will be equivalent to: SELECT emp_no FROM employees WHERE dpt_no = ''; I think its because PHP engine is an interpreter not a compiler, which can't foresee variable definitions. This is acceptable but frustrating for newcomers from complied programming languages. Even if you try to be smart and define the variable before the query but pass it a value from a variable defied after the query declaration this will not work either.

« previous php.notes (#188811) next »