Just a note about auto incremental ids and rollback. When using transactions and inserting into a table containing a column with auto incremental ids, the id will be incremented even though the transaction is rolled back. This might occupy a lot of ids if a lot of rollbacks are performed. Example: autocommit(FALSE); $mysqli->query(„CREATE TABLE TestTable ( `id_column` INT NOT NULL AUTO_INCREMENT , `content` INT NOT NULL , PRIMARY KEY ( `id_column` )) ENGINE = InnoDB;“); $mysqli->commit(); $mysqli->query(„INSERT INTO TestTable (content) VALUES (99)“); $mysqli->commit(); $mysqli->query(„INSERT INTO TestTable (content) VALUES (99)“); $mysqli->query(„INSERT INTO TestTable (content) VALUES (99)“); $mysqli->query(„INSERT INTO TestTable (content) VALUES (99)“); $mysqli->rollback(); $mysqli->query(„INSERT INTO TestTable (content) VALUES (99)“); $mysqli->commit(); if ($result = $mysqli->query(„SELECT id_column FROM TestTable“)) { while($row = $result->fetch_row()) { printf(„Id: %d.n“, $row[0]); } $result->close(); } $mysqli->query(„DROP TABLE TestTable“); $mysqli->close(); ?> This will output: Id: 1. Id: 5.
Наши спонсори са:
Български трактори на добри цени при изключително качество