HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP mysqli_stmt_init() Function

PHP MySQLi Reference PHP MySQLi Reference

Example

Initialize a statement and return an object to use with mysqli_stmt_prepare():

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$city="Sandnes";

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

if (mysqli_stmt_prepare($stmt,"SELECT District FROM City WHERE Name=?"))
  {

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

  // Execute query
  mysqli_stmt_execute($stmt);

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

  // Fetch value
  mysqli_stmt_fetch($stmt);

  printf("%s is in district %s",$city,$district);

  // Close statement
  mysqli_stmt_close($stmt);
  }

mysqli_close($con);
?>

Definition and Usage

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


Syntax

mysqli_stmt_init(connection);

Parameter Description
connection Required. Specifies the MySQL connection to use

Technical Details

Return Value: Returns an object
PHP Version: 5+


PHP MySQLi Reference PHP MySQLi Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE