Friday, 15 June 2012

mysql - Using a prepared statement in php & mysqli -


I am using the statement prepared for the first time and I can not choose to work for some reason, all these records Returns, but I can not find them in the variable I know that it returns all the records, because if I call echo '1'; adds to the loop, then it echoes for each record.

Any help would be great code below:

  function bilittits ($ quote_id) {if ($ stmt = $ this-> link-> gt; ; Prepare ("Select * FROM` 0_quotes_items`` where WHET__ quote_id` =?")) {// Bind a variable in the parameter as a string $ Stmt-> Bind_param ("i", $ quote_id); // Execute the statement $ Stmt-> Executed (); While ($ line = $ stmt-> fetch ()) {echo $ line ['id']; } // Close the statement made $ Stmt-> near (); }}  

Update: In the error log, I see the following error after adding ($ row = $ stmt-> fetch_assoc ( )) { As suggested by:

PHP Fatal Error: Undefined method mysqli_stmt :: fetch_assoc ()

call me The same problem was found in a link, but I do not understand how to correct any assistance in relation to the example would be great.

PHP MySQLi fetch method of bracket notation Does not reach query data by using: $ row ['id'] .

So I get two options to remedy: first find this row:

  while ($ line = $ stmt-> fetch ()) {< / Code> 

... and modify it, either , first add the bind_result method, and then access the data in slightly different ways:

  $ stmt-> Bind_result ($ id, $ other, $ whatnot); // while reclaiming in query 3 columns while accepting ($ line = $ stmt-> fetch ()) {resonant "$ id $ other $ whatnot 
"; }

... or , first use the result object's fetch_assoc method and Use Fetch_assoc instead of fetch :

  $ result = $ stmt-> Get_result (); ($ Row = $ result-> fetch_assoc ()) { 

Now you can use table column names as keys to access query data in your loop: $ row ['id'] .


For PHP MySQLi method, you need to use bind_result . By doing this you can call your data with the variable names that you have bound it

To use the field name as the result array index, such as: $ row [ 'Id'] , you need to use the PHP MySQLi method and to first use fetch_assoc / Code> need to access the method.


No comments:

Post a Comment