I’ve been using the old MySQL library for PHP for ages now and I’ve finally caved into using MySQLi. Prepared statements seem very useful, so I’m trying to get the hang out them.
Right now I’m creating some prepared statements and binding their parameters globally, and then using a function to execute them like this:
$stmt = $mysqli->prepare("INSERT ...");
$stmt->bind_param("ss", $var1, $var2);
function process($t) {
global $mysqli, $stmt;
$var1 = $t['var1'];
$var2 = $t['var2'];
$stmt->execute();
}
The problem I’m running into is that the execute function runs into an error where the variables are still null. Should I be binding/unbinding as I gather values from $t?
I’m such a dummy:
I thought that MySQLi was doing some magic binding with variables.
In this case
bind_paramjust places the values in the prepared statement, rather than declaring in stone that certain variables are ‘bound’ to the statement.