note 108093 added to function.mysql-query

From: Date: Wed, 28 Mar 2012 03:11:15 +0000
Subject: note 108093 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-186884@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 2.88.223.7 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/108093 Del: integrated -- https://master.php.net/note/delete/108093/integrated Del: useless -- https://master.php.net/note/delete/108093/useless Del: bad code -- https://master.php.net/note/delete/108093/bad+code Del: spam -- https://master.php.net/note/delete/108093/spam Del: non-english -- https://master.php.net/note/delete/108093/non-english Del: in docs -- https://master.php.net/note/delete/108093/in+docs Del: other reasons-- https://master.php.net/note/delete/108093 Reject -- https://master.php.net/note/reject/108093 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186884) next »