i using prepared statement crud in php. code snippet :
$sql="insert dress(dressid, description, size, price, entrydate, categoryid, colorid) values (?, ?, ?, ?, ?, ?, ?) on duplicate key update description=?, size=?, price=?, entrydate=?, categoryid=?, colorid=?"; $stmt=$connection->prepare($sql); $stmt->bind_param("ssssss", $colorid, $color, $color);
then, have repeat variables binding in bind_param
function, bind_param("sssssssss", $var1, $var2, $var1, $var2, $var3..)
. there way shorten binding?
you can pass parameters ->execute()
method, this:
$stmt->execute([123, 'red', 'green', ... ]);
if keep parameters in array, instead of assigning them variables, binding them prepared statement can become rather trivial.
Comments
Post a Comment