English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial Básico PHP

Tutorial Avançado PHP

PHP & MySQL

Manual de Referência PHP

Uso e exemplo da função PHP mysqli_stmt_init()

PHP MySQLi Reference Manual

A função mysqli_stmt_init() inicializa a declaração e retorna o objeto usado por mysqli_stmt_prepare().

Definição e uso

mysqli_stmt_init()A função mysqli_stmt_prepare() é usada para inicializar o objeto da declaração. O resultado desta função pode ser passado como um parâmetro para mysqli_stmt_prepare() Função.

Sintaxe

mysqli_stmt_init($con);

Parâmetros

Serial numberParameters and descriptions
1

con(Required)

This is an object representing the connection with the MySQL Server.

Return value

This function returns a statement object.

PHP version

This function was originally introduced in PHP version5introduced and can be used in all higher versions.

Online example

The following example demonstratesmysqli_stmt_init()Function usage (procedural style)-

<?php
   //Establish connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   $query = "CREATE TABLE Test(Name VARCHAR(255), AGE INT)"; 
   mysqli_query($con, $query);
   //Initialize statement
   $stmt =  mysqli_stmt_init($con);
   $res = mysqli_stmt_prepare($stmt, "INSERT INTO Test values(?, ?)");
   mysqli_stmt_bind_param($stmt, "si", $Name, $Age);
   $Name = 'Raju';
   $Age = 25;
   print("Insert record.....");
   //Execute statement
   mysqli_stmt_execute($stmt);
   //End statement
   mysqli_stmt_close($stmt);
   //Close connection
   mysqli_close($con);
?>

Output result

Insert record.....

Online example

Here is another example of this function, initializing the declaration and returning the object used by mysqli_stmt_prepare():

<?php
   //Establish connection
   $con = new mysqli("localhost", "root", "password", "mydb");
   $query = "CREATE TABLE Test(Name VARCHAR(255), AGE INT)"; 
   $con->query($query);
   //Initialize statement
   $stmt =  $con->stmt_init();
   $res = $stmt->prepare("INSERT INTO Test values(?, ?)");
   $stmt->bind_param("si", $Name, $Age);
   $Name = 'Raju';
   $Age = 25;
   print("Insert record.....");
   //Execute statement
   $stmt->execute();
   //End statement
   $stmt->close();
   //Close connection
   $con->close();
?>

Output result

Insert record.....

PHP MySQLi Reference Manual