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

Manuale di base PHP

Manuale avanzato PHP

PHP e MySQL

Manuale di riferimento PHP

Uso e esempio della funzione mysqli_stmt_param_count() in PHP

PHP MySQLi Manuale di riferimento

La funzione mysqli_stmt_param_count() restituisce il numero di parametri della query specificata.

定义和用法

mysqli_stmt_param_count()函数接受一个(准备好的)语句对象作为参数,并返回其中的参数标记数。

语法

mysqli_stmt_param_count($stmt)

参数

序号参数及说明
1

stmt(必需)

这是表示执行SQL查询的语句的对象。

返回值

PHP mysqli_stmt_param_count()函数返回一个整数值,该整数值指示给定的预处理语句中参数标记的数量。

PHP版本

此函数最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。

Esempio online

假设我们已经在MySQL数据库中创建了一个名为employee的表,其内容如下:

mysql> select * from employee;
+------------+--------------+------+------+--------+
| FIRST_NAME     | LAST_NAME                 | AGE            | SEX            | INCOME         |
+------------+--------------+------+------+--------+
| Vinay           | Bhattacharya             |     20 | M            |         21000 |
| Sharukh        | Sheik                         |     25 | M            |         23300 |
| Trupthi        | Mishra                     |     24 | F            |          51000 |
| Sheldon        | Cooper                     |     25 | M            |           2256 |
| Sarmista     | Sharma                     |     28 | F            |         15000 |
+------------+--------------+------+------+--------+
5 rows in set (0.00 sec)

以下示例演示了 mysqli_stmt_param_count() 函数的用法(面向过程风格)-

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   $stmt = mysqli_prepare($con, "UPDATE employee set INCOME=INCOME-? where INCOME>=?");
   mysqli_stmt_bind_param($stmt, "si", $reduct, $limit);
   $limit = 20000;
   $reduct = 5000;
   //Esegui la statement
   mysqli_stmt_execute($stmt);
   print("Registrazione aggiornata......\n");
   //Righe interessate
   $count = mysqli_stmt_param_count($stmt);
   //Fine della statement
   mysqli_stmt_close($stmt);
   //Chiudi la connessione
   mysqli_close($con);
   print("Righe interessate ".$count);
?>

Risultato di output

Registrazione aggiornata......
Righe interessate 3

Esempio online

Nel linguaggio orientato agli oggetti, la sintassi di questa funzione è$stmt->param_count;.Di seguito è riportato un esempio di questa funzione in stile orientato agli oggetti;

<?php
   //Stabilisci la connessione
   $con = new mysqli("localhost", "root", "password", "mydb");
   $con -> query("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");
   $stmt = $con -> prepare("INSERT INTO myplayers values(?, ?, ?, ?, ?)");
   $stmt -> bind_param("issss", $id, $fname, $lname, $pob, $country);
   $id = 1;
   $fname = 'Shikhar';
   $lname = 'Dhawan';
   $pob = 'Delhi';
   $country = 'India';
   //Esegui la statement
   $stmt->execute();
   //Registrazione aggiornata
   $count = $stmt ->param_count;
   print("Numero di parametri: ".$count);
   //Fine della statement
   $stmt->close();
   //Chiudi la connessione
   $con->close();
?>

Risultato di output

Numero di parametri: 5

PHP MySQLi Manuale di riferimento