/** * Returns the ID of the last inserted row * * @param string $database * Unusued for this factory * @param string $name * Unused in this factory class * @return string|null * Key value */ public static function LastInsertId($database = null, $name = null) { return SDBStatement::LastInsertId(); }
// INSERT // ------- // Create an object for using with bindObject (although we could bind each value // individually if we prefer $car = new Car(); $car->colour = 'red'; $car->brand = 'Alfa Romeo'; // "Prepare" an sql statement $query = new SDBStatement("INSERT INTO cars (colour, brand) VALUES (:colour, :brand)"); // Bind the object's properties to the query placeholders $query->bindObject($car); // Execute the statement $query->execute(); // The autogenerated itemName is echo "ID: ", SDBStatement::LastInsertId(); // ------- // UPDATE // ------- // "Prepare" an sql statement $query = new SDBStatement("UPDATE cars SET colour = :colour WHERE brand = :brand"); // Bind when executing: $query->execute(array(':colour' => 'red', ':brand' => 'Alfa Romeo')); // ------- // DELETE // ------- $query = new SDBStatement("DELETE FROM cars WHERE colour = :colour"); // Bind a value to :colour $query->bindValue(':colour', 'red'); // Execute the query $query->execute(); // The query "SELECT * FROM cars WHERE colour = red'" will now return zero results