Prepared statements in php

Many of the more mature databases support the concept of prepared statements. They have following advantages :
1) The query only needs to be parsed (or prepared) once, but can be executed multiple times with the same or different parameters. When the query is prepared, the database will analyze, compile and optimize its plan for executing the query. For complex queries this process can take up enough time that it will noticeably slow down an application if there is a need to repeat the same query many times with different parameters. By using a prepared statement the application avoids repeating the analyze/compile/optimize cycle. This means that prepared statements use fewer resources and thus run faster.
 
2) The parameters to prepared statements don’t need to be quoted; the driver automatically handles this. If an application exclusively uses prepared statements, the developer can be sure that no SQL injection will occur (however, if other portions of the query are being built up with unescaped input, SQL injection is still possible).

<?php
$mysqli = new mysqli('localhost', 'root', '', 'test');
/* check connection */
if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n", mysqli_connect_error());
	exit();
}
$stmt = $mysqli->prepare("INSERT INTO newrecords VALUES (?, ?)");
// bind_param(<s for string, s for string>,parameter1, paremeter2)
$stmt->bind_param('ss', $Name, $Class);

$Name = 'John';
$Class = 'MS';

/* execute prepared statement */

$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);

/* close statement and connection */

$stmt->close();
/* close connection */
$mysqli->close();
?>

Various Bind types have the following values

BIND TYPE COLUMN TYPE
i All INT types
d DOUBLE and FLOAT
b BLOBs
s All other types