Prepared Statements
Prepare Statements are used to create the queries more secure and give better performance.
There are 2 types of prepared statement
1. Executes data manipulation statemenet
2. executes data retrieval statements
Example:
$con = mysqli_connect($host,$uname,$pass,$dbname)
$sql = ‘INSERT INTO user VALUES(?, ?)’;
$stmt = mysqli_stmt_init($con);
if (mysqli_stmt_prepare($stmt, $sql)) {
mysqli_stmt_bind_param($stmt, ‘is’, $name, $age);
$nam = “test”;
$age = ‘23′;
mysqli_stmt_execute($stmt);
}
In the above code
1.mysqli_stmt_init($con)
Above line will initialiaze a statement.
2.After initialize the statement we have to bind the varibles to the statement. In the above code following line will to that thing.
mysqli_stmt_bind_param($stmt, ‘is’, $name, $age);
3. Then we have to execute the query. In the above code following line will to that thing.
mysqli_stmt_execute($stmt)
