bind_param() in MYSQLI

$query="UPDATE  student SET class=?,mark=? WHERE id=?";
Student Table : Sample Data and query to create table
config.php Database connection object $connection is taken from config.php 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);
}
Bind parameters to a prepared statement as parameter.

Returns True on success and False on failure.

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.

? ( question mark ) is used as placeholder for each value in the 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
No need to use mysqli_real_escape_string() if you are using bind_param()

MySQL DUMP of student table

MYSQLI Functions mysql_query() : Apply query to database
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





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