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.mysqli::stmt_init
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
mysqli::stmt_init
Референца за `mysqli.stmt-init.php` со подобрена типографија и навигација.
mysqli::stmt_init
mysqli_stmt_init
класата mysqli_driver
mysqli::stmt_init -- mysqli_stmt_init — Иницира изјава и враќа објект за употреба со mysqli_stmt_prepare
= NULL
Напиши целосна ознака на елемент
Процедурален стил
Алоцира и иницира објект за изјава погоден за mysqli_stmt_prepare().
Забелешка:
Сите последователни повици до која било функција mysqli_stmt ќе откажат додека mysqli_stmt_prepare() беше повикана.
Параметри
-
mysql објектот како свој прв аргумент. mysqli Само процедурален стил: А mysqli_connect() or mysqli_init()
Вратени вредности
Враќа објект.
Белешки од корисници 2 забелешки
you can use $stmt = $mysqli->prepare(); directly without stmt-init() . i think there is no need for stmt-init .