PHP mysqli: begin_transaction() function
mysqli_begin_transaction function / mysqli::begin_transaction
The mysqli_begin_transaction function / mysqli::begin_transaction — Starts a transaction
Syntax:
Object oriented style(method)
public bool mysqli::begin_transaction ([ int $flags [, string $name ]] )
Procedural style
bool mysqli_begin_transaction ( mysqli $link [, int $flags [, string $name ]] )
Usage: Procedural style
begin_transaction ([ int $flags [, string $name ]] );
Parameter:
Name | Description | Required/Optional |
---|---|---|
Link | Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init() | Required for Procedural style and Optional for object oriented style |
flags | Valid flags are: MYSQLI_TRANS_START_READ_ONLY: Start the transaction as "START TRANSACTION READ ONLY". MYSQLI_TRANS_START_READ_WRITE: Start the transaction as "START TRANSACTION READ WRITE". MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT: Start the transaction as "START TRANSACTION WITH |
Riquired |
name | Savepoint name for the transaction. |
Return value:
Returns TRUE on success or FALSE on failure.
Version: PHP 5, PHP 7
Example of object oriented style:
<?php
$mysqli = new mysqli("localhost", "user1", "datasoft123", "hr");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$mysqli->begin_transaction(MYSQLI_TRANS_START_READ_ONLY);
$mysqli->query("SELECT first_name, last_name FROM actor");
$mysqli->commit();
$mysqli->close();
?>
Example of procedural style:
<?php
$link = mysqli_connect("localhost", "user1", "datasoft123", "hr");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_begin_transaction($link, MYSQLI_TRANS_START_READ_ONLY);
mysqli_query($link, "SELECT first_name, last_name FROM actor LIMIT 1");
mysqli_commit($link);
mysqli_close($link);
?>
See also
Previous: autocommit
Next: change_user
PHP: Tips of the Day
PHP - how to create a newline character?
Only double quoted strings interpret the escape sequences \r and \n as '0x0D' and '0x0A' respectively, so you want:
"\r\n"
Single quoted strings, on the other hand, only know the escape sequences \\ and \'.
So unless you concatenate the single quoted string with a line break generated elsewhere (e. g., using double quoted string "\r\n" or using chr function chr(0x0D).chr(0x0A)), the only other way to have a line break within a single quoted string is to literally type it with your editor:
$s = 'some text before the line break some text after';
Make sure to check your editor for its line break settings if you require some specific character sequence (\r\n for example).
Ref : https://bit.ly/3hcyege
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook