English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_stmt_param_count() function returns the number of parameters for the given statement.
mysqli_stmt_param_count()The function accepts a (prepared) statement object as a parameter and returns the number of parameter markers within it.
mysqli_stmt_param_count($stmt)
Serial Number | Parameters and Description |
---|---|
1 | stmt (required) This is the object representing the statement used to execute the SQL query. |
The PHP mysqli_stmt_param_count() function returns an integer value indicating the number of parameter markers in the given prepared statement.
This function was initially introduced in PHP version5introduced and can be used in all higher versions.
Assuming we have already created a table named employee in the MySQL database, its content is as follows:
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)
The following examples demonstrate mysqli_stmt_param_count() Function Usage (Procedural Style)-
<?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; //Execute statement mysqli_stmt_execute($stmt); print("Record updated......\n"); //Rows affected $count = mysqli_stmt_param_count($stmt); //End statement mysqli_stmt_close($stmt); //Close connection mysqli_close($con); print("Rows affected ",$count); ?>
Output result
Record updated...... Rows affected 3
In the object-oriented style, the syntax of this function is$stmt->param_count;.Here is an example of this function in an object-oriented style;
<?php //Establish connection $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("Creating table.....\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'; //Execute statement $stmt->execute(); //Record updated $count = $stmt ->param_count; print("Number of parameters: ",$count); //End statement $stmt->close(); //Close connection $con->close(); ?>
Output result
Number of parameters: 5