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.
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.
Syntax
Following below is the syntax to use this function -
mysqli_stmt_param_count($stmt);
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | stmt(Mandatory) 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.
Example1
Assuming we have created a table named employee in the MYSQL database with the following contents $minus;
mysql> select * from employee; +------------+--------------+------+------+--------+ | FIRST_NAME | LAST_NAME | AGE | SEX | INCOME | +------------+--------------+------+------+--------+ | 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) -
<?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; //Executing the statement mysqli_stmt_execute($stmt); print("Records Updated......\n"); //Affected rows $count = mysqli_stmt_param_count($stmt); //Closing the statement mysqli_stmt_close($stmt); //Closing the connection mysqli_close($con); print("Rows affected ".$count); ?>
Output
When the above code is executed, it will produce the following result -
Records Updated...... Rows affected 3
Example2
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 -
<?php //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 $stmt->execute(); //Affected rows $count = $stmt ->param_count; print("Number of parameters: ".$count); //Closing the statement $stmt->close(); //Closing the connection $con->close(); ?>
Output
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.
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.