PHP 8.5.0 Alpha 1 available for testing

mysqli_stmt::$param_count

mysqli_stmt_param_count

(PHP 5, PHP 7, PHP 8)

mysqli_stmt::$param_count -- mysqli_stmt_param_countDevuelve el número de parámetros de un comando SQL

Descripción

Estilo orientado a objetos

Estilo procedimental

mysqli_stmt_param_count(mysqli_stmt $statement): int

Devuelve el número de variables esperadas por el comando preparado stmt.

Parámetros

statement

Solo estilo procedimental: Un objeto mysqli_stmt devuelto por mysqli_stmt_init().

Valores devueltos

Devuelve un entero que representa el número de parámetros.

Ejemplos

Ejemplo #1 Estilo orientado a objetos

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

/* Verifica la conexión */
if (mysqli_connect_errno()) {
printf("Fallo en la conexión: %s\n", mysqli_connect_error());
exit();
}

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

$marker = $stmt->param_count;
printf("La consulta tiene %d variables.\n", $marker);

/* Cierre del comando */
$stmt->close();
}

/* Cierre de la conexión */
$mysqli->close();
?>

Ejemplo #2 Estilo procedimental

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

/* Verifica la conexión */
if (mysqli_connect_errno()) {
printf("Fallo en la conexión: %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 consulta tiene %d variables.\n", $marker);

/* Cierre del comando */
mysqli_stmt_close($stmt);
}

/* Cierre de la conexión */
mysqli_close($link);
?>

Los ejemplos anteriores mostrarán :

La consulta tiene 2 variables.

Ver también

add a note

User Contributed Notes 1 note

up
1
Senthryl
16 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