mysqli::stmt_init

mysqli_stmt_init

(PHP 5)

mysqli::stmt_init -- mysqli_stmt_initInitializes a statement and returns an object for use with mysqli_stmt_prepare

Description

Object oriented style

mysqli_stmt mysqli::stmt_init ( void )

Procedural style

mysqli_stmt mysqli_stmt_init ( mysqli $link )

Allocates and initializes a statement object suitable for mysqli_stmt_prepare().

Note:

Any subsequent calls to any mysqli_stmt function will fail until mysqli_stmt_prepare() was called.

Parameters

link

Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

Return Values

Returns an object.

See Also

Коментарии

you can use $stmt = $mysqli->prepare(); directly without stmt-init() . i think there is no need for stmt-init .
2014-06-08 02:58:25
http://php5.kiev.ua/manual/ru/mysqli.stmt-init.html
Автор:
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:

<?php
$db 
$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:

<?php
$db 
$this->getConnection()->getDbConnection();
$preparedQuery $db->stmt_init();
$preparedQuery->prepare ($query);
?>

resolved the problem.
2016-09-01 00:32:03
http://php5.kiev.ua/manual/ru/mysqli.stmt-init.html

    Поддержать сайт на родительском проекте КГБ