A transaction is a continuous set of database operations, as if it were a single unit of work. In other words, it will never be a complete transaction unless each individual operation within that group is successful. If any operation in the transaction fails, the entire transaction fails.
In fact, the club many SQL queries into a group that will execute all the people together as part of the transaction.
Attributes of the transaction:
Transactions have abbreviated acid for the following four standard properties, commonly referred to as:
- Atomicity: Ensure that all operations within the work unit are completed successfully, otherwise the transaction will be aborted at the point of failure, and the previous operation will be rolled back to the previous state.
- Consistency: A transaction that is successfully committed after the database has been correctly changed to state.
- Isolation: Enables transactions to operate independently and transparently from one another.
- Persistence: Ensures that the results or effects of a committed transaction still exist in the event of a system failure.
- In MySQL, a transaction starts working and ending with a commit or ROLLBACK statement. A large number of transactions are formed between the SQL commands for the start and end statements.
- COMMIT & ROLLBACK:
- These two keyword submissions and rollbacks are primarily used for MySQL transactions.
- When a successful transaction completes, the commit command should cause all participating table changes to take effect.
- In the event of a failure, you should issue one of the tables referenced in the transaction returned by the rollback command to the previous state.
The transaction behavior that can be controlled is called the autocommit set session variable. If Autocommit is set to 1 (the default), then each SQL statement (in transaction or not) is considered a complete transaction and is committed by default when it is completed. When Autocommit is set to 0 o'clock, the set autocommit = 0 command is issued, and the subsequent sequence of statements acts like a transaction until a definite commit statement is made, and no activity is committed.
You can execute these SQL commands in PHP by using the mysql_query () function.
Examples of common transactions
This sequence of events is independent of the programming language used and can be built in any language used to create the logical path of the application.
You can execute these SQL commands in PHP by using the mysql_query () function.
- Begin work start transaction issue SQL command
- Issue one or more SQL commands, such as select,insert,update or delete
- Check if there are any errors, everything is based on the needs.
- If there are any errors, then the problem rollback the command, or a commit is issued.
Transaction security table types in MySQL:
If you plan to use MySQL transaction programming, you need a special way to create a table. There are many support transactions but the most popular is the InnoDB table type.
When compiling MySQL from source code, the InnoDB table supports the need for specific compilation parameters. If the MySQL version does not have INNODB support, ask the Internet service provider to establish a version of MySQL support InnoDB table type, or download and install Windows or Linux/unix Mysql-max binary distribution and use the table types in the development environment.
If the MySQL installation supports InnoDB tables, simply add a TYPE=INNODB definition table creation statement. For example, the following code creates a InnoDB table tcount_tbl:
root@host# mysql-u root-p password;
Enter password:*******
mysql> use tutorials;
Database changed
mysql> create TABLE Tcount_tbl
-> (
-> tutorial_author-varchar () not NULL,
-> tutorial_count INT
->) Type=innodb;
Query OK, 0 rows affected (0.05 sec)
Please check the links below for more information about: InnoDB
You can use other Gemini or BDB table types, but it depends on your installation if it supports both types.