1$stmt = $mysqli->prepare("INSERT INTO testtable VALUES (?,?,?)");
2// prepare() can fail because of syntax errors, missing privileges, ....
3if ( false===$stmt ) {
4 // and since all the following operations need a valid/ready statement object
5 // it doesn't make sense to go on
6 // you might want to use a more sophisticated mechanism than die()
7 // but's it's only an example
8 die('prepare() failed: ' . htmlspecialchars($mysqli->error));
9}
10
11$rc = $stmt->bind_param('iii', $x, $y, $z);
12// bind_param() can fail because the number of parameter doesn't match the placeholders in the statement
13// or there's a type conflict(?), or ....
14if ( false===$rc ) {
15 // again execute() is useless if you can't bind the parameters. Bail out somehow.
16 die('bind_param() failed: ' . htmlspecialchars($stmt->error));
17}
18
19$rc = $stmt->execute();
20// execute() can fail for various reasons. And may it be as stupid as someone tripping over the network cable
21// 2006 "server gone away" is always an option
22if ( false===$rc ) {
23 die('execute() failed: ' . htmlspecialchars($stmt->error));
24}
25
26$stmt->close();
27