bind_param() in MYSQLI

Object Oriented Style
$stmt->bind_param('sii', $class, $mark, $id);
Procedural style
mysqli_stmt_bind_param($stmt, "si",$class, $id);
Used with prepare() to bind parameters to variables used inside Query.

$stmt : Statement identifier

Types : 'siid': We used 4 digits here so four variables can be matched, Here is the list of Types

i: Integer , tiny small medium
s: String
d: Double
b: Bolb

MySQLI database connection file

<?Php
require "config.php";// Database connection file.

$class='Three';
$mark=66;
$id=5;
$query="UPDATE  student SET class=?,mark=? WHERE id=?";
$stmt = $connection->prepare($query);
if ($stmt) {
$stmt->bind_param('sii', $class, $mark, $id);
$stmt->execute();
echo "Record Updated:";
echo $stmt->affected_rows;
}else{
echo $connection->error;
}
?>
Procedural style
$class='Three';
$mark=68;
$id=5;
$query="UPDATE  student SET class=?,mark=? WHERE id=?";
if ($stmt = mysqli_prepare($connection,$query)){
mysqli_stmt_bind_param($stmt, "sii", $class, $mark, $id);
mysqli_stmt_execute($stmt);
echo "Record Updated:";
echo mysqli_affected_rows($connection);

}else{
echo mysqli_error($connection);
}
No need to use mysqli_real_escape_string() if you are using bind_param()

MySQL DUMP of student table

Visitors Rating
Your Rating





Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer