We now have a youtube channel. Subscribe!

PHP | mysqli_stmt_param_count() Function

PHP mysqli_stmt_param_count() Function

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP mysqli_stmt_param_count() Function.

The PHP mysqli_stmt_param_count() function accepts a prepared statement object as a parameter and then returns the number of parameter markers in it.


Following below is the syntax to use this function -


Parameter Details

Sr.NoParameter & Description


This is an object representing a statement executing an SQL query.

Return Value

This PHP function returns an integer value which indicates the number of parameter markers in the given prepared statement.

PHP Version

This built-in PHP function was first introduced in PHP version 5 and works in all the later versions.


Assuming we have created a table named employee in the MYSQL database with the following contents $minus;

mysql> select * from employee;
| Kennedy    | Nkpara       |   27 | M    |  21000 |
| Paul       | Francis      |   30 | M    |  23300 |
| Stephanie  | Francis      |   24 | F    |  51000 |
| Justice    | Donald       |   28 | M    |   2256 |
| Precious   | Amah         |   25 | F    |  15000 |
5 rows in set (0.00 sec)

The following below is an example which demonstrates the usage of the built-in PHP mysqli_stmt_param_count() function (in a procedural style) -

   $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;

   //Executing the statement
   print("Records Updated......\n");

   //Affected rows
   $count = mysqli_stmt_param_count($stmt);

   //Closing the statement

   //Closing the connection

   print("Rows affected ".$count);


When the above code is executed, it will produce the following result -

Records Updated......
Rows affected 3


In an object oriented style the syntax of this function is $stmt->param_count(); Following is the example of this function in an object oriented style -

   //Creating a 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("Table Created.....\n");

   $stmt = $con -> prepare( "INSERT INTO myplayers values(?, ?, ?, ?, ?)");
   $stmt -> bind_param("issss", $id, $fname, $lname, $pob, $country);
   $id = 1;
   $fname = 'Kennedy';
   $lname = 'Nkpara';
   $pob = 'PortHarcourt';
   $country = 'Nigeria';

   //Executing the statement

   //Affected rows
   $count = $stmt ->param_count;
   print("Number of parameters: ".$count);

   //Closing the statement

   //Closing the connection


When the above code is executed, it will produce the following result -

Table Created.....
Records Deleted.....
Number of parameters: 5

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP mysqli_stmt_prepare() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain