MySQLi Tutorial MySQLi References

mysqli_stmt $param_count Property



The mysqli_stmt::$param_count / mysqli_stmt_param_count() function returns the number of parameter markers present in the prepared statement.

Syntax

//Object-oriented style
$mysqli_stmt->param_count;

//Procedural style
mysqli_stmt_param_count(statement)

Parameters

statement Required. For procedural style only: Specify a mysqli_stmt object returned by mysqli_stmt_init().

Return Value

Returns an integer representing the number of parameters.

Example: Object-oriented style

The example below shows the usage of mysqli_stmt::$param_count property.

<?php
//establishing connection to the database
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_param_count) {
  echo "Failed to connect to MySQL: ". $mysqli->connect_error;
  exit();
}

$sql = "INSERT INTO Employee (Name, City, Salary) VALUES (?, ?, ?)";
if ($stmt = $mysqli->prepare($sql)) {

  $marker = $stmt->param_count;
  printf("Statement has %d markers.\n", $marker);

  //closing the statement
  $stmt->close();
}

//closing the connection
$mysqli->close();
?>

The output of the above code will be similar to:

Statement has 3 markers.

Example: Procedural style

The example below shows the usage of mysqli_stmt_param_count() function.

<?php
//establishing connection to the database
$mysqli = mysqli_connect("localhost", "user", "password", "database");
if (mysqli_connect_param_count()) {
  echo "Failed to connect to MySQL: ". mysqli_connect_error();
  exit();
}

$sql = "INSERT INTO Employee (Name, City, Salary) VALUES (?, ?, ?)";
if ($stmt = mysqli_prepare($mysqli, $sql)) {

  $marker = mysqli_stmt_param_count($stmt);
  printf("Statement has %d markers.\n", $marker);

  //closing the statement
  mysqli_stmt_close($stmt);
}

//closing the connection
mysqli_close($mysqli);
?>

The output of the above code will be similar to:

Statement has 3 markers.

❮ MySQLi Functions Reference