What is the correct way to use bind_param in PHP mysqli?

When using bind_param in PHP mysqli, it is important to ensure that the data types of the variables being bound match the data types of the placeholders in the SQL query. This helps prevent SQL injection attacks and ensures proper data handling. To use bind_param correctly, you need to specify the data types of the variables being bound and pass them by reference.

// Assuming $mysqli is your mysqli connection object and $name and $age are variables to bind
$stmt = $mysqli->prepare("INSERT INTO table_name (name, age) VALUES (?, ?)");
$name = "John";
$age = 30;
$stmt->bind_param("si", $name, $age);
$stmt->execute();
$stmt->close();