PHP 7.1.0 Release Candidate 5 Released



(PHP 5, PHP 7)

mysqli::stmt_init -- mysqli_stmt_initInicializa una sentencia y devuelve un objeto para usarlo con mysqli_stmt_prepare


Estilo orientado a objetos

mysqli_stmt mysqli::stmt_init ( void )

Estilo por procedimientos

mysqli_stmt mysqli_stmt_init ( mysqli $link )

Asigna e inicializa un objeto de sentencia apropiado para mysqli_stmt_prepare().


Cualquier llamada subsiguiente a cualquier función de mysqli_stmt fallará a menos que se llame antes a mysqli_stmt_prepare().



Sólo estilo por procediminetos: Un identificador de enlace devuelto por mysqli_connect() o mysqli_init()

Valores devueltos

Returns an object.

Ver también

add a note add a note

User Contributed Notes 3 notes

mamdo7 at hotmail dot com
2 years ago
you can use $stmt = $mysqli->prepare(); directly without stmt-init() . i think there is no need for stmt-init .
Jeff C
1 month ago
stmt_init() seems to clear previous (possibly erroneous) results on the DB connection, which means you don't necessarily need to use it but it could make the code more robust.

In a PHPUnit test, I had a sequence of prepared queries on the same connection. One of them fetched a row from a SELECT but didn't keep fetching until it drained the connection, so it left some stale results. When the next query did this:

= $this->getConnection()->getDbConnection();
$preparedQuery = $db->prepare ($query);

the prepare() call generated an error: "Could not prepare query: Commands out of sync; you can't run this command now." Changing to this:

= $this->getConnection()->getDbConnection();
$preparedQuery = $db->stmt_init();
$preparedQuery->prepare ($query);

resolved the problem.
Deepak Sati
1 year ago
If your sql query has some errors and you don't use stmt_init() before preparing the statement, you won't get error message for wrong sql query.
To Top