mysqli_stmt::$param_count
(mysqli_stmt_param_count) Returns the number of parameters of the given statement
The mysqli_stmt::$param_count() function is used to obtain the number of parameters in the preprocessing statement.
usage:
int mysqli_stmt::$param_count( void )
parameter:
This function has no parameters.
Return value:
Returns an integer representing the number of parameters in the preprocessing statement.
Example:
$conn = new mysqli("localhost", "username", "password", "database"); if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } $sql = "INSERT INTO users (name, email) VALUES (?, ?)"; $stmt = $conn->prepare($sql); if ($stmt === false) { die("预处理失败: " . $conn->error); } // 获取预处理语句中参数的个数$paramCount = $stmt->param_count(); echo "预处理语句中参数的个数为: " . $paramCount; $stmt->close(); $conn->close();
Output result:
预处理语句中参数的个数为: 2
In the example above, we first establish a connection to the database, and then prepare a preprocessing statement for the INSERT statement. Use the $stmt->param_count()
function to get the number of parameters in the preprocessing statement, here are 2. Finally, the preprocessing statement and database connection are closed.