{"id":4427,"date":"2024-07-31T09:38:22","date_gmt":"2024-07-31T02:38:22","guid":{"rendered":"https:\/\/www.sqlservertutorial.net\/?page_id=4427"},"modified":"2024-08-18T10:15:33","modified_gmt":"2024-08-18T03:15:33","slug":"php-sql-server-transaction","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/","title":{"rendered":"PHP SQL Server: Transaction"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.<\/p>\n\n\n\n<p class=\"note\">This tutorial begins where\u00a0the <a href=\"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-delete\/\">deleting data in a table from PHP tutorial<\/a>\u00a0left off.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='creating-sample-data'>Creating sample data <a href=\"#creating-sample-data\" class=\"anchor\" id=\"creating-sample-data\" title=\"Anchor for Creating sample data\">#<\/a><\/h2>\n\n\n\n<p>Step 1. Open SQL Server Management Studio (SSMS) and connect to the <code>BookStore<\/code> database on your SQL Server.<\/p>\n\n\n\n<p>Step 2. Execute the following statements to insert books into the Books table, assign these books to the author with id 2, and update inventories for these books in the Inventories table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">INSERT INTO Books (Title, Publisher, ISBN, PublishedDate) VALUES\n(<span class=\"hljs-string\">'Mastering SQL: A Comprehensive Guide'<\/span>, <span class=\"hljs-string\">'Tech Books Publishing'<\/span>, <span class=\"hljs-string\">'978-1234567890'<\/span>, <span class=\"hljs-string\">'2022-01-15'<\/span>),\n(<span class=\"hljs-string\">'The Art of Database Design'<\/span>, <span class=\"hljs-string\">'Expert Press'<\/span>, <span class=\"hljs-string\">'978-0987654321'<\/span>, <span class=\"hljs-string\">'2021-06-10'<\/span>),\n(<span class=\"hljs-string\">'SQL Queries for Mere Mortals'<\/span>, <span class=\"hljs-string\">'Practical SQL Publishing'<\/span>, <span class=\"hljs-string\">'978-1122334455'<\/span>, <span class=\"hljs-string\">'2023-03-21'<\/span>),\n(<span class=\"hljs-string\">'Advanced SQL Programming Techniques'<\/span>, <span class=\"hljs-string\">'Pro Code Press'<\/span>, <span class=\"hljs-string\">'978-6677889900'<\/span>, <span class=\"hljs-string\">'2020-09-30'<\/span>),\n(<span class=\"hljs-string\">'Database Systems: Theory and Practice'<\/span>, <span class=\"hljs-string\">'Academic Press'<\/span>, <span class=\"hljs-string\">'978-5566778899'<\/span>, <span class=\"hljs-string\">'2022-11-05'<\/span>);\n\n<span class=\"hljs-keyword\">DECLARE<\/span> @BookID1 INT, @BookID2 INT, @BookID3 INT, @BookID4 INT, @BookID5 INT;\n\nSELECT @BookID1 = BookID FROM Books WHERE ISBN = <span class=\"hljs-string\">'978-1234567890'<\/span>;\nSELECT @BookID2 = BookID FROM Books WHERE ISBN = <span class=\"hljs-string\">'978-0987654321'<\/span>;\nSELECT @BookID3 = BookID FROM Books WHERE ISBN = <span class=\"hljs-string\">'978-1122334455'<\/span>;\nSELECT @BookID4 = BookID FROM Books WHERE ISBN = <span class=\"hljs-string\">'978-6677889900'<\/span>;\nSELECT @BookID5 = BookID FROM Books WHERE ISBN = <span class=\"hljs-string\">'978-5566778899'<\/span>;\n\n-- Insert records into the BookAuthors table\nINSERT INTO BookAuthors (BookID, AuthorID)\nVALUES (@BookID1, <span class=\"hljs-number\">2<\/span>),\n       (@BookID2, <span class=\"hljs-number\">2<\/span>),\n       (@BookID3, <span class=\"hljs-number\">2<\/span>),\n       (@BookID4, <span class=\"hljs-number\">2<\/span>),\n       (@BookID5, <span class=\"hljs-number\">2<\/span>);\n\nINSERT INTO Inventories (BookID, Qty)\nSELECT BookID, ABS(CHECKSUM(NEWID()) % <span class=\"hljs-number\">101<\/span>) + <span class=\"hljs-number\">100<\/span>\nFROM Books;\n\n\n-- Insert customers\nINSERT INTO &#91;dbo].&#91;Customers] (FirstName, LastName, Email, PhoneNumber, Address) VALUES\n(<span class=\"hljs-string\">'John'<\/span>, <span class=\"hljs-string\">'Doe'<\/span>, <span class=\"hljs-string\">'john.doe@gmail.com'<\/span>, <span class=\"hljs-string\">'123-456-7890'<\/span>, <span class=\"hljs-string\">'123 Elm Street, Springfield, IL 62701'<\/span>),\n(<span class=\"hljs-string\">'Jane'<\/span>, <span class=\"hljs-string\">'Smith'<\/span>, <span class=\"hljs-string\">'jane.smith@yahoo.com'<\/span>, <span class=\"hljs-string\">'234-567-8901'<\/span>, <span class=\"hljs-string\">'456 Oak Avenue, Metropolis, NY 10001'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='performing-a-transaction'>Performing a transaction <a href=\"#performing-a-transaction\" class=\"anchor\" id=\"performing-a-transaction\" title=\"Anchor for Performing a transaction\">#<\/a><\/h2>\n\n\n\n<p>Create a new file <code>orderdb.php<\/code> and define the <code>OrderDB<\/code> class that handles the transaction:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">OrderDB<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">__construct<\/span><span class=\"hljs-params\">(private \\PDO $conn)<\/span>\n    <\/span>{\n        <span class=\"hljs-keyword\">$this<\/span>-&gt;conn = $conn;\n    }\n\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">create<\/span><span class=\"hljs-params\">($customerId, $bookId, $quantity, $price, $orderDate)<\/span>\n    <\/span>{\n        <span class=\"hljs-keyword\">try<\/span> {\n            <span class=\"hljs-comment\">\/\/ Begin a transaction<\/span>\n            <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;beginTransaction();\n\n            <span class=\"hljs-comment\">\/\/ Check inventory<\/span>\n            <span class=\"hljs-keyword\">$this<\/span>-&gt;checkInventory($bookId, $quantity);\n\n            <span class=\"hljs-comment\">\/\/ Insert order and get the new order ID<\/span>\n            $orderId = <span class=\"hljs-keyword\">$this<\/span>-&gt;insertOrder($customerId, $orderDate, $price * $quantity);\n\n            <span class=\"hljs-comment\">\/\/ Insert order details<\/span>\n            <span class=\"hljs-keyword\">$this<\/span>-&gt;insertOrderDetails($orderId, $bookId, $quantity, $price);\n\n            <span class=\"hljs-comment\">\/\/ Update inventory<\/span>\n            <span class=\"hljs-keyword\">$this<\/span>-&gt;updateInventory($bookId, $quantity);\n\n            <span class=\"hljs-comment\">\/\/ Commit the transaction<\/span>\n            <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;commit();\n\n            <span class=\"hljs-keyword\">return<\/span> $orderId;\n\n        } <span class=\"hljs-keyword\">catch<\/span> (<span class=\"hljs-keyword\">Exception<\/span> $e) {\n            <span class=\"hljs-comment\">\/\/ Rollback the transaction on error<\/span>\n            <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;rollBack();\n            <span class=\"hljs-keyword\">throw<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-keyword\">Exception<\/span>(<span class=\"hljs-string\">\"Failed to create order: \"<\/span> . $e-&gt;getMessage());\n        }\n    }\n\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">checkInventory<\/span><span class=\"hljs-params\">($bookId, $quantity)<\/span>\n    <\/span>{\n        $sql = <span class=\"hljs-string\">'SELECT Qty FROM Inventories WHERE BookId = :bookId'<\/span>;\n        $stmt = <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;prepare($sql);\n        $stmt-&gt;execute(&#91;<span class=\"hljs-string\">'bookId'<\/span> =&gt; $bookId]);\n        $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);\n\n        <span class=\"hljs-keyword\">if<\/span> ($row === <span class=\"hljs-keyword\">false<\/span> || $row&#91;<span class=\"hljs-string\">'Qty'<\/span>] &lt; $quantity) {\n            <span class=\"hljs-keyword\">throw<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-keyword\">Exception<\/span>(<span class=\"hljs-string\">\"Insufficient inventory\"<\/span>);\n        }\n    }\n\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">insertOrder<\/span><span class=\"hljs-params\">($customerId, $orderDate, $totalAmount)<\/span>\n    <\/span>{\n        $sql = <span class=\"hljs-string\">'INSERT INTO Orders (OrderDate, CustomerId, TotalAmount) \n                VALUES (:orderDate, :customerId, :totalAmount)'<\/span>;\n\n        $stmt = <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;prepare($sql);\n        $stmt-&gt;execute(&#91;\n            <span class=\"hljs-string\">'orderDate'<\/span> =&gt; $orderDate,\n            <span class=\"hljs-string\">'customerId'<\/span> =&gt; $customerId,\n            <span class=\"hljs-string\">'totalAmount'<\/span> =&gt; $totalAmount\n        ]);\n\n        <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;lastInsertId();\n    }\n\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">insertOrderDetails<\/span><span class=\"hljs-params\">($orderId, $bookId, $quantity, $price)<\/span>\n    <\/span>{\n        $sql = <span class=\"hljs-string\">'INSERT INTO OrderDetails (OrderId, BookId, Quantity, Price) \n                VALUES (:orderId, :bookId, :quantity, :price)'<\/span>;\n\n        $stmt = <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;prepare($sql);\n        \n        $stmt-&gt;execute(&#91;\n            <span class=\"hljs-string\">'orderId'<\/span> =&gt; $orderId,\n            <span class=\"hljs-string\">'bookId'<\/span> =&gt; $bookId,\n            <span class=\"hljs-string\">'quantity'<\/span> =&gt; $quantity,\n            <span class=\"hljs-string\">'price'<\/span> =&gt; $price\n        ]);\n    }\n\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">updateInventory<\/span><span class=\"hljs-params\">($bookId, $quantity)<\/span>\n    <\/span>{\n        $sql = <span class=\"hljs-string\">\"UPDATE Inventories \n                SET Qty = Qty - :quantity \n                WHERE BookId = :bookId\"<\/span>;\n\n        $stmt = <span class=\"hljs-keyword\">$this<\/span>-&gt;conn-&gt;prepare($sql);\n        $stmt-&gt;execute(&#91;\n            <span class=\"hljs-string\">'quantity'<\/span> =&gt; $quantity,\n            <span class=\"hljs-string\">'bookId'<\/span> =&gt; $bookId\n        ]);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='running-the-app'>Running the app <a href=\"#running-the-app\" class=\"anchor\" id=\"running-the-app\" title=\"Anchor for Running the app\">#<\/a><\/h2>\n\n\n\n<p>Step 1. Modify the <code>index.php<\/code> file to create an order using the <code>create()<\/code> method of an <code>OrderDB<\/code> object:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n<span class=\"hljs-keyword\">require_once<\/span> <span class=\"hljs-string\">'orderdb.php'<\/span>;\n\n<span class=\"hljs-comment\">\/\/ Connect to the SQL Server<\/span>\n$conn = <span class=\"hljs-keyword\">require_once<\/span> <span class=\"hljs-string\">'connect.php'<\/span>;\n$orderDB = <span class=\"hljs-keyword\">new<\/span> OrderDB($conn);\n\n<span class=\"hljs-comment\">\/\/ Create a new order<\/span>\n$customerId = <span class=\"hljs-number\">1<\/span>;\n$bookId = <span class=\"hljs-number\">1<\/span>;\n$quantity = <span class=\"hljs-number\">5<\/span>;\n$price = <span class=\"hljs-number\">19.99<\/span>;\n$orderDate = <span class=\"hljs-string\">'2024-07-31'<\/span>;\n\n$orderId = $orderDB-&gt;create(\n    $customerId,\n    $bookId,\n    $quantity,\n    $price,\n    <span class=\"hljs-string\">'2024-07-27'<\/span>\n);\n\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"New Order ID: \"<\/span> . $orderId;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Step 2. Run the <code>index.php<\/code> on the web browser. It&#8217;ll return the following output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">New<\/span> Order ID: <span class=\"hljs-number\">1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This means that the application has successfully created an order with <code>ID<\/code> 1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Call the <code>beginTransaction()<\/code> method of the PDO object to start a transaction.<\/li>\n\n\n\n<li>Call the <code>commit()<\/code> method of the PDO object to apply the changes permanently to the database.<\/li>\n\n\n\n<li>Call the <code>rollback()<\/code> method of the PDO object to roll back the transaction.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"4427\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/\"\n\t\t\t\tdata-post-title=\"PHP SQL Server: Transaction\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"4427\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/\"\n\t\t\t\tdata-post-title=\"PHP SQL Server: Transaction\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4375,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4427","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP SQL Server: Transaction<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP SQL Server: Transaction\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-18T03:15:33+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/php-sql-server\\\/php-sql-server-transaction\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/php-sql-server\\\/php-sql-server-transaction\\\/\",\"name\":\"PHP SQL Server: Transaction\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"datePublished\":\"2024-07-31T02:38:22+00:00\",\"dateModified\":\"2024-08-18T03:15:33+00:00\",\"description\":\"In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/php-sql-server\\\/php-sql-server-transaction\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/php-sql-server\\\/php-sql-server-transaction\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/php-sql-server\\\/php-sql-server-transaction\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP SQL Server\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/php-sql-server\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP SQL Server: Transaction\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP SQL Server: Transaction","description":"In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/","og_locale":"en_US","og_type":"article","og_title":"PHP SQL Server: Transaction","og_description":"In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.","og_url":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2024-08-18T03:15:33+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/","url":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/","name":"PHP SQL Server: Transaction","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"datePublished":"2024-07-31T02:38:22+00:00","dateModified":"2024-08-18T03:15:33+00:00","description":"In this tutorial, you will learn how to perform a transaction on an SQL Server using PHP PDO.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/php-sql-server-transaction\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"PHP SQL Server","item":"https:\/\/www.sqlservertutorial.net\/php-sql-server\/"},{"@type":"ListItem","position":3,"name":"PHP SQL Server: Transaction"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/4427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=4427"}],"version-history":[{"count":5,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/4427\/revisions"}],"predecessor-version":[{"id":4510,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/4427\/revisions\/4510"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/4375"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=4427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}