PHP 8.3.4 Released!

mysqli_stmt::$param_count

mysqli_stmt_param_count

(PHP 5, PHP 7, PHP 8)

mysqli_stmt::$param_count -- mysqli_stmt_param_countRetourne le nombre de paramètres d'une commande SQL

Description

Style orienté objet

Style procédural

mysqli_stmt_param_count(mysqli_stmt $statement): int

Retourne le nombre de variables attendues par la commande préparée stmt.

Liste de paramètres

statement

Style procédural uniquement : Un objet mysqli_stmt retourné par la fonction mysqli_stmt_init().

Valeurs de retour

Retourne un entier représentant le nombre de paramètres.

Exemples

Exemple #1 Style orienté objet

<?php
$mysqli
= new mysqli("localhost", "my_user", "my_password", "world");

/* Vérifie la connexion */
if (mysqli_connect_errno()) {
printf("Échec de la connexion : %s\n", mysqli_connect_error());
exit();
}

if (
$stmt = $mysqli->prepare("SELECT Name FROM Country WHERE Name=? OR Code=?")) {

$marker = $stmt->param_count;
printf("La requête a %d variables.\n", $marker);

/* Fermeture de la commande */
$stmt->close();
}

/* Fermeture de la connexion */
$mysqli->close();
?>

Exemple #2 Style procédural

<?php
$link
= mysqli_connect("localhost", "my_user", "my_password", "world");

/* Vérifie la connexion */
if (mysqli_connect_errno()) {
printf("Échec de la connexion : %s\n", mysqli_connect_error());
exit();
}

if (
$stmt = mysqli_prepare($link, "SELECT Name FROM Country WHERE Name=? OR Code=?")) {

$marker = mysqli_stmt_param_count($stmt);
printf("La requête a %d variables.\n", $marker);

/* Fermeture de la commande */
mysqli_stmt_close($stmt);
}

/* Fermeture de la connexion */
mysqli_close($link);
?>

Les exemples ci-dessus vont afficher :

La requête a 2 variables.

Voir aussi

add a note

User Contributed Notes 1 note

up
2
Senthryl
15 years ago
This parameter (and presumably any other parameter in mysqli_stmt) will raise an error with the message "Property access is not allowed yet" if the statement was not prepared properly, or not prepared at all.

To prevent this, always ensure that the return value of the "prepare" statement is true before accessing these properties.
To Top