English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP MySQLi Manuale di Referenza
mysqli_stmt_store_result()函数从准备好的语句存储结果集。
mysqli_stmt_store_result()函数接受语句对象作为参数,并在执行SELECT,SHOW或DESCRIBE语句时在本地存储给定语句的结果集。
mysqli_stmt_store_result($stmt);
序号 | 参数及说明 |
---|---|
1 | stmt(必需) 这是表示准备好的语句的对象。 |
2 | offset(必需) 这是表示所需行的整数值(必须在 0 到 结果集中的行总数 之间)。 |
PHP mysqli_stmt_attr_get()函数返回一个布尔值,如果成功,则返回TRUE;如果失败,则返回FALSE.
此函数最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。
以下示例演示了mysqli_stmt_store_result();函数的用法(面向过程风格)-
<?php $con = mysqli_connect("localhost", "root", "password", "mydb"); mysqli_query($con, "CREATE TABLE Test(Name VARCHAR(255), AGE INT)"); mysqli_query($con, "insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27)"); print("Creazione della tabella.....\n"); //Leggi il record $stmt = mysqli_prepare($con, "SELECT * FROM Test"); //Esegui la statement mysqli_stmt_execute($stmt); //Memorizza i risultati mysqli_stmt_store_result($stmt); //Righe $count = mysqli_stmt_num_rows($stmt); print("Righe nella tabella: ".$count."\n"); //Fine della statement mysqli_stmt_close($stmt); //Chiudi la connessione mysqli_close($con); ?>
Risultato dell'output
Creazione della tabella..... Righe nella tabella: 3
Nello stile orientato agli oggetti, la sintassi di questa funzione è$stmt->store_result();。Ecco un esempio di questa funzione in uno stile orientato agli oggetti;
<?php //Stabilisci la connessione $con = new mysqli("localhost", "root", "password", "mydb"); $con->query("CREATE TABLE Test(Name VARCHAR(255), AGE INT)"); $con->query("insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27)"); print("Creazione della tabella.....\n"); $stmt = $con->prepare("SELECT * FROM Test"); //Esegui la statement $stmt->execute(); //Memorizza i risultati $stmt->store_result(); print("Righe".$stmt->num_rows); //Fine della statement $stmt->close(); //Chiudi la connessione $con->close(); ?>
Risultato dell'output
Creazione della tabella..... Righe: 3