PHP 8.3.4 Released!

mysqli::stmt_init

mysqli_stmt_init

(PHP 5, PHP 7, PHP 8)

mysqli::stmt_init -- mysqli_stmt_initInitialisiert eine Anweisung und liefert ein Objekt für die Verwendung mit mysqli_stmt_prepare

Beschreibung

Objektorientierter Stil

public mysqli::stmt_init(): mysqli_stmt|false

Prozeduraler Stil

mysqli_stmt_init(mysqli $mysql): mysqli_stmt|false

Erstellt und initialisiert ein Anweisungs-Objekt, das für die Funktion mysqli_stmt_prepare() geeignet ist.

Hinweis:

Alle nachfolgenden Aufrufe einer mysqli_stmt-Funktion schlagen solange fehl, bis mysqli_stmt_prepare() aufgerufen wurde.

Parameter-Liste

mysql

Nur bei prozeduralem Aufruf: ein von mysqli_connect() oder mysqli_init() zurückgegebenes mysqli-Objekt.

Rückgabewerte

Gibt ein Objekt zurück.

Siehe auch

add a note

User Contributed Notes 2 notes

up
19
Jeff C
7 years 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:

<?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.
up
6
mamdo7 at hotmail dot com
9 years ago
you can use $stmt = $mysqli->prepare(); directly without stmt-init() . i think there is no need for stmt-init .
To Top