"how to use mysqli prepared statements?" Code Answer

5

from the mysqli::prepare docs:

the parameter markers must be bound to application variables using mysqli_stmt_bind_param() and/or mysqli_stmt_bind_result() before executing the statement or fetching rows.

bind_param docs.

i.e.:

$name = 'one';
$age  = 1;

$stmt = $mysqli->prepare("insert into users (name, age) values (?,?)");

// bind parameters. i'm guessing 'string' & 'integer', but read documentation.
$stmt->bind_param('si', $name, $age);

// *now* we can execute
$stmt->execute();
By cmn on January 12 2022

Answers related to “how to use mysqli prepared statements?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.