PHP mysqli_stmt_init() Function

Definition

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

Syntax

PHP mysqli_stmt_init() Function has the following syntax.

mysqli_stmt_init(connection);

Parameter

  • connection - Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

Return

Returns an object.

Example


<?php//from w w  w .j  a va 2 s .  com
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$city="New York";
$stmt=mysqli_stmt_init($con);
if (mysqli_stmt_prepare($stmt,"SELECT District FROM City WHERE Name=?")){
  mysqli_stmt_bind_param($stmt,"s",$city);  // Bind parameters
  mysqli_stmt_execute($stmt);               // Execute query
  mysqli_stmt_bind_result($stmt,$district); // Bind result variables
  mysqli_stmt_fetch($stmt);                 // Fetch value
  print $district;
  mysqli_stmt_close($stmt);
}

mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions