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.
mysqli_stmt::$param_count
mysqli_stmt_param_count
(PHP 5)
mysqli_stmt::$param_count -- mysqli_stmt_param_count — Retourne le nombre de paramètre d'une commande SQL
Description
Style orienté objet
Style procédural
Retourne le nombre de variables attendues par la commande préparée stmt.
Liste de paramètres
-
stmt -
Style procédural uniquement : Un identifiant de requête 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.
Senthryl
10-Mar-2009 11:47
