note 71994 added to function.mysqli-stmt-fetch

From: Date: Thu, 28 Dec 2006 01:55:31 +0000
Subject: note 71994 added to function.mysqli-stmt-fetch
Groups: php.notes 
Request: Send a blank email to php-notes+get-120974@lists.php.net to get a copy of this message
Just a side note, I see many people are contributing in ways to help return result sets for prepared statements in ASSOSITAVE arrays the same as the mysqli_fetch_assos function might return from a normal query issued via mysqli_query. This is done, in all the examples I have seen, by dynamically getting the field names in the prepared statement and binding them using 'variable' variables, which are variables that are created dynamically with the name of the field names. Some thing though you should take into consideration is illegal variable names in PHP. Assume that you have a field name in your database table named 'My Field' , notice the space between 'My' and 'Field'. To dynamically create this variable is illegal in PHP as variables can not have spaces in them. Furthermore, you won't be able to access the binded data as you can not reference a variable like so: <?php // Syntax Error. echo $My Table; ?> The only suitable solution I find now is to replace all spaces in a field name with an underscore so that you can use the binded variable like so: <?php // This Works. echo $My_Table; // Notice the space is now replaced with an underscore. ?> All you simply have to do is before you dynamically bind the data, so a string search for any spaces in the table name, replace them with an underscore, THEN bind the variable. That way you should not run into problems. ---- Server IP: 66.163.161.117 Probable Submitter: 84.36.231.206 ---- Manual Page -- http://www.php.net/manual/en/function.mysqli-stmt-fetch.php Edit -- https://master.php.net/note/edit/71994 Del: integrated -- https://master.php.net/note/delete/71994/integrated Del: useless -- https://master.php.net/note/delete/71994/useless Del: bad code -- https://master.php.net/note/delete/71994/bad+code Del: spam -- https://master.php.net/note/delete/71994/spam Del: non-english -- https://master.php.net/note/delete/71994/non-english Del: in docs -- https://master.php.net/note/delete/71994/in+docs Del: other reasons-- https://master.php.net/note/delete/71994 Reject -- https://master.php.net/note/reject/71994 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120974) next »