Fonction PHP mysqli_stmt_init ()

Définition et utilisation

le mysqli_stmt_init()La fonction est utilisée pour initialiser un objet instruction. Le résultat de cette fonction peut être passé comme l'un des paramètres de la fonction mysqli_stmt_prepare () .

Syntaxe

mysqli_stmt_init($con);

Paramètres

Sr. Non Paramètre et description
1

con(Mandatory)

Il s'agit d'un objet représentant une connexion à MySQL Server.

Valeurs de retour

Cette fonction renvoie un objet instruction.

Version PHP

Cette fonction a été introduite pour la première fois dans la version 5 de PHP et fonctionne dans toutes les versions ultérieures.

Exemple

L'exemple suivant montre l'utilisation de la fonction mysqli_stmt_init () (dans le style procédural) -

<?php
   //Creating the connection
   $con = mysqli_connect("localhost", "root", "password", "mydb");

   $query = "CREATE TABLE Test(Name VARCHAR(255), AGE INT)"; 
   mysqli_query($con, $query);

   //initiating the 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("Record Inserted.....");

   //Executing the statement
   mysqli_stmt_execute($stmt);

   //Closing the statement
   mysqli_stmt_close($stmt);

   //Closing the connection
   mysqli_close($con);
?>

Cela produira le résultat suivant -

Record Inserted.....

Exemple

Voici un autre exemple de cette fonction $ minus;

<?php
   //Creating the connection
   $con = new mysqli("localhost", "root", "password", "mydb");

   $query = "CREATE TABLE Test(Name VARCHAR(255), AGE INT)"; 
   $con->query($query);

   //initiating the statement
   $stmt =  $con->stmt_init();

   $res = $stmt->prepare("INSERT INTO Test values(?, ?)");
   $stmt->bind_param("si", $Name, $Age);
   $Name = 'Raju';
   $Age = 25;
   print("Record Inserted.....");

   //Executing the statement
   $stmt->execute();

   //Closing the statement
   $stmt->close();

   //Closing the connection
   $con->close();
?>

Cela produira le résultat suivant -

Record Inserted.....