What is the correct way to bind parameters in a prepared statement in PHP?

When using prepared statements in PHP, it is important to bind parameters properly to prevent SQL injection attacks. The correct way to bind parameters in a prepared statement in PHP is to use the bind_param method, specifying the data type of each parameter. This ensures that the parameters are properly sanitized before being executed in the database query.

// Assuming $conn is your database connection and $name and $age are the parameters to bind
$stmt = $conn->prepare("INSERT INTO table_name (name, age) VALUES (?, ?)");
$stmt->bind_param("si", $name, $age); // "si" denotes string and integer data types
$stmt->execute();