mysqli: can it prepare multiple queries in one statement?

A prepared statement can only execute one MySQL query. You can prepare as many statements as you want in different variables:

$stmtUser = $sql->prepare("INSERT INTO user (id_user, username, pw, email) VALUES (?,?,?,?)");
$stmtProc = $sql->prepare("INSERT INTO process (id_user, idp) VALUES (?,?);");

And then execute them later. If you want to ensure that neither one is ever run unless both are able to run, then you need to look into transactions, like Thomas said.

Also, a general tip: “call to member function on a non-object” is the standard error you get when prepare() fails and so $stmt isn’t actually a prepared statement object. It usually means you need to look for an error in your prepare() statement rather than anything later.

Leave a Comment