I also need to use mysqli for a prepared statement. Can someone point me to a complete example of a prepared statement from connecting to an insert to an error handling selection
You can also use PDO, which I prefer. Actually, it looks like you are confusing PDO and Mysqli in your sample code.
$db = new PDO($dsn, $user, $pass); $stmt = $db->prepare("INSERT INTO users (name, age) VALUES (?,?)"); $stmt->execute(array($name1, $age1)); $stmt->execute(array($name2, $age2));
Unlike mysqli, you do not need to call a separate binding function, although this function is available if you prefer / want / should use it.
Another fun thing about PDO is called placeholders, which can be much less confusing in complex queries:
$db = new PDO($dsn, $user, $pass); $stmt = $db->prepare("INSERT INTO users (name, age) VALUES (:name,:age)"); $stmt->execute(array(':name' => $name1, ':age' => $age1)); $stmt->execute(array(':name' => $name2, ':age' => $age2));
source share