Parameter Binding in MySQLi : mysqli « MySQL Database « PHP






Parameter Binding in MySQLi

 
<?php

    $mysqli = mysqli_connect("hostname", "user", "pass", "database");

    if(mysqli_connect_errno()) {

        die("Could not connect: ".mysqli_connect_error());

    }
    /* 
        CREATE TABLE books(name VARCHAR(255),
                           isbn VARCHAR(10),
                           price FLOAT)
    */

    $bookname = "PHP";
    $bookisbn = "11111111111";
    $bookprice = 49.95;

    $stmt = mysqli_prepare($mysqli, "INSERT INTO books VALUES(?, ?, ?)");

    mysqli_bind_param($stmt, "ssd", $bookname, $bookisbn, $bookprice);
    mysqli_execute($stmt);

    mysqli_stmt_close($stmt);
    mysqli_close($mysqli);

?>
  
  








Related examples in the same category

1.Multiple Queries Using MySQLi
2.Use mysqli to fetch data from mysql
3.Using the mysqli Object-Oriented API
4.Using the Object-Oriented Syntax in MySQLi
5.mysqli_fetch_object.php
6.mysqli_fetch_result-2.php
7.mysqli_fetch_result.php
8.mysqli_fetch_row.php
9.mysqli_free_result.php
10.mysqli_multi_query.php
11.mysqli_stmt_prepare.php
12.mysqli_store_result.php
13.retrieving_multiple_rows.php