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!
";
}
}