Why can't I use MYSQLI's prepared statements in PHP to query data in the database (binding parameters or binding results), Project emergencies

Source: Internet
Author: User
Why can't I use MYSQLI's prepared statement in PHP to query the data in the database (binding parameters or binding results), the project urgently!
The code is as follows:

/*
Using mysqli extensions to bind results
*/
New Server Connection
$mysqli =new mysqli (' localhost ', ' root ', ' root ', ' searcdb ');
Create a query
$query = "Select Adminname,adminpwd from Admininfo";
To create a statement object
$stmt = $mysqli->stmt_init ();
Preparing statements for execution
$stmt->prepare ($query);
EXECUTE statement
$stmt->execute ();
Binding result Parameters
$stmt->bind_result ($name, $pwd);
Cycle results and output data
while ($stmt->fetch ()) {

", $name, $pwd);
}
Recover Statement Resources
$stmt->close ();
Close connection
$mysqli->close ();
?>
What's the problem with this statement? I directly do the additions and deletions can be, but whether it is the use of mysqli binding results or the method of binding parameters are not, for the hero guidance Ah, the company will soon use it to do the project, emergency emergencies!!


------Solution--------------------
printf ("%s,%s,%s
", $name, $pwd);???

One parameter is missing.
or one more format character,
------Solution--------------------
One more placeholder. Don't you only have two parameters?
------Solution--------------------
One line of code is missing, and the query results can be stored temporarily for use.
For reference only:

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, Time);
$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" = Time
);
Array_push ($arrLink, $arr);
}
return $arrLink;
}else{
echo "Failed to query Order details!
";
}
}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.