Why can't I use the prepared mysqli statement in php to query database data (bind parameters or bind results)? the project is in urgent need! The code is as follows: PHPcode & lt ;? Php/* use mysqli extension to bind the result * // Create a server connection $ why can't mysql use the mysqli preparation statement in php to query data in the database (bind parameters or bind results), urgent project use!
The code is as follows:
PHP code
Stmt_init (); // prepare the statement for execution $ stmt-> prepare ($ query); // execute the statement $ stmt-> execute (); // bind_result ($ name, $ pwd); // cyclically process the result and output the data while ($ stmt-> fetch ()) {printf ("% s, % s, % s
", $ Name, $ pwd);} // restore statement resource $ stmt-> close (); // close the connection $ mysqli-> close ();?>
What is the problem with this statement? I can directly add, delete, modify, and query the statement, but neither use the mysqli binding result nor the method for binding parameters. could you please help me, the company's internship will soon be used as a project, and it will be urgently used !!
------ Solution --------------------
Printf ("% s, % s, % s
", $ Name, $ pwd );???
A parameter is missing.
Or an extra formatted character.
------ Solution --------------------
Add one more placeholder. Don't you only have two parameters?
------ Solution --------------------
If one line of code is missing, you must temporarily store the query results for use.
For reference only:
PHP code
Function selectLink ($ oid) {$ SQL = "select o. oid, l. lid, c. cid, comName, comPrice, ordTime from mis_order o, mis_link l, mis_commodity c where o. oid = l. lid and c. cid = l. cid and o. oid =? "; $ Stmt = $ this-> mysqli-> prepare ($ SQL); $ stmt-> bind_param (" I ", $ oid); $ stmt-> execute (); $ stmt-> store_result (); $ stmt-> bind_result ($ oid, $ lid, $ cid, $ comName, $ comPrice, $ ordTime ); $ rows = $ stmt-> affected_rows; if ($ rows> 0) {$ arrLink = array (); while ($ stmt-> fetch ()) {$ arr = array ("oid" => $ oid, "lid" => $ lid, "cid" => $ cid, "comName" => $ comName, "comPrice" => $ comPrice, "ordTime" => $ ordTime); array _ Push ($ arrLink, $ arr);} return $ arrLink;} else {echo "an error occurred while querying order details!
";}}