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

Tutoriale PHP Base

Tutoriale PHP Avanzato

PHP & MySQL

Manuale PHP

Uso e esempio della funzione PHP mysqli_stmt_reset()

PHP MySQLi Manuale di riferimento

La funzione mysqli_stmt_reset() riimposta la statement preparata

Definizione e uso

mysqli_stmt_reset()La funzione accetta come parametro un oggetto di statement pronta (aperta in precedenza) e la riimposta, ovvero cambia il reset degli errori, dei result set non in cache e dei dati inviati. Le query, i binding e i result set memorizzati non saranno modificati.

Sintassi

mysqli_stmt_reset($stmt);

Parametro

NumeroParametri e spiegazioni
1

con(obbligatorio)

Questo è l'oggetto della statement pronta.

Valore di ritorno

La funzione PHP mysqli_stmt_reset() restituisce un valore booleano, true nel caso di successotrue, nel caso di fallimento èfalse.

Versione PHP

Questa funzione è stata introdotta originariamente nella versione PHP 5 e può essere utilizzata in tutte le versioni successive.

Online example

Esempio di utilizzo:mysqli_stmt_reset()Uso della funzione (stile procedurale)-

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))");
   print("Creazione della tabella.....\n");
   mysqli_query($con, "INSERT INTO myplayers values(1, 'Sikhar', 'Dhawan', 'Delhi', 'India')");
   mysqli_query($con, "INSERT INTO myplayers values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");
   print("Inserimento record.....\n");
   //Ricerca del contenuto della tabella
   $stmt = mysqli_prepare($con, "SELECT * FROM myplayers");
   //Esegui la dichiarazione
   mysqli_stmt_execute($stmt);
   $res = mysqli_stmt_reset($stmt);
   if($res){
      print("Reset successful");	
   }
   //Binding the values in the result to variables
   $res = mysqli_stmt_bind_result($stmt, $id, $fname, $lname, $pob, $country);
   while (mysqli_stmt_fetch($stmt)) {
      print("Id: ".$id."\n");
      print("fname: ".$fname."\n");
      print("lname: ".$lname."\n");
      print("pob: ".$pob."\n");
      print("country: ".$country."\n");
      print("\n");
   }
   //Fine della dichiarazione
   mysqli_stmt_close($stmt);
   //Chiudi la connessione
   mysqli_close($con);
?>

Risultato dell'output

Inserting record.....
Reset successful

Since we reset the statement in the middle, the content of the result will not be printed without the reset function, and the program will generate the following output-

Inserting record.....
Reset Eseguito con successo
E:\PHPExamples>php procedure_oriented.php
Creazione della tabella.....
Inserting record.....
Id: 1
fname: Sikhar
lname: Dhawan
pob: Delhi
country: India
Id: 2
fname: Jonathan
lname: Trott
pob: CapeTown
country: SouthAfrica

Online example

In the object-oriented style, the syntax of this function is$stmt->close();。Below is an example of this function in an object-oriented style;

<?php
   //Establishing connection
   $con = new mysqli("localhost", "root", "password", "mydb");
   //Creating a table
   $con -> query("CREATE TABLE players(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))");
   print("Creazione della tabella.....\n");
   //Utilizzando le dichiarazioni preparate per inserire valori nella tabella
   $stmt = $con -> prepare("INSERT INTO players values(?, ?, ?, ?, ?)");
   $res = $stmt->reset();
   if($res){
      print("Reset Eseguito con successo");	
   }
   //Leggendo valori ai marker dei parametri
   $stmt -> bind_param("issss", $id, $fname, $lname, $pob, $country);
   $id = 1;
   $fname = 'Shikhar';
   $lname = 'Dhawan';
   $pob = 'Delhi';
   $country = 'India';
   //Esegui la dichiarazione
   $stmt->execute();
   //Fine della dichiarazione
   $stmt->close();
   //Chiudi la connessione
   $con->close();
?>

Risultato dell'output

Creazione della tabella.....
Reset Eseguito con successo

E il contenuto della tabella giocatori sarà vuoto-

mysql> drop table players;
Query OK, 0 righe influenzate (0.26 sec)

Se rimuovi la funzione reset() e esegui il programma sopra, il contenuto della tabella players sarà come segue:

mysql> select * from players;
+------+------------+-----------+----------------+---------+
| ID         | First_Name         | Last_Name         | Place_Of_Birth         | Country         |
+------+------------+-----------+----------------+---------+
|         1         | Shikhar         | Dhawan         | Delhi                         | India         |
+------+------------+-----------+----------------+---------+
1 riga nel set (0.00 sec)

PHP MySQLi Manuale di riferimento