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.
require "config.php";// Database connection file.

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

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


* indicates required
Subscribe to plus2net

    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 All rights reserved worldwide Privacy Policy Disclaimer