Easy Tutorial
❮ Func Array Intersect Key Filter Validate Int ❯

PHP mysqli_stmt_init() Function

PHP MySQLi Reference Manual

Initializes a statement and returns an object for use with mysqli_stmt_prepare():

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
// Change database connection character set to utf8
mysqli_set_charset($con, "utf8");

$country = "CN";

// Create a prepared statement
$stmt = mysqli_stmt_init($con);

if (mysqli_stmt_prepare($stmt, "SELECT name FROM websites WHERE country=?"))
{

    // Bind parameters
    mysqli_stmt_bind_param($stmt, "s", $country);

    // Execute the query
    mysqli_stmt_execute($stmt);

    // Bind result variables
    mysqli_stmt_bind_result($stmt, $name);

    // Fetch the value
    mysqli_stmt_fetch($stmt);

    printf("%s country's website is: %s", $country, $name);

    // Close the prepared statement
    mysqli_stmt_close($stmt);
}

mysqli_close($con);
?>

Definition and Usage

The mysqli_stmt_init() function initializes a statement and returns an object for use with mysqli_stmt_prepare().


Syntax

Parameter Description
connection Required. Specifies the MySQL connection to use.

Technical Details

Return Value: Returns an object.
PHP Version: 5+
--- ---
❮ Func Array Intersect Key Filter Validate Int ❯