You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$tsql2 = "UPDATE SalesLT.SalesOrderDetail SET OrderQty = (OrderQty + 1) WHERE ProductID = 709";
65
-
$stmt2 = sqlsrv_query($conn, $tsql2);
65
+
/* Set up and execute the second query. */
66
+
$tsql2 = "UPDATE SalesLT.SalesOrderDetail SET OrderQty = (OrderQty + 1) WHERE ProductID = 709";
67
+
$stmt2 = sqlsrv_query($conn, $tsql2);
66
68
67
-
/* If both queries were successful, commit the transaction. */
68
-
/* Otherwise, rollback the transaction. */
69
-
if($stmt1 && $stmt2)
70
-
{
71
-
sqlsrv_commit($conn);
72
-
?>
73
-
<h1> Transaction was commited </h1>
69
+
/* If both queries were successful, commit the transaction. */
70
+
/* Otherwise, rollback the transaction. */
71
+
if ($stmt1 && $stmt2) {
72
+
sqlsrv_commit($conn);
73
+
?>
74
+
<h1> Transaction was commited </h1>
74
75
75
-
<?php
76
-
77
-
}
78
-
else
79
-
{
80
-
sqlsrv_rollback($conn);
81
-
echo"Transaction was rolled back.\n";
82
-
}
76
+
<?php
77
+
78
+
} else {
79
+
sqlsrv_rollback($conn);
80
+
echo"Transaction was rolled back.\n";
81
+
}
83
82
84
-
/* Free statement and connection resources. */
85
-
sqlsrv_free_stmt($stmt1);
86
-
sqlsrv_free_stmt($stmt2);
83
+
/* Free statement and connection resources. */
84
+
sqlsrv_free_stmt($stmt1);
85
+
sqlsrv_free_stmt($stmt2);
87
86
88
87
?>
89
88
<?php
90
-
//////////////////UDF/////////////////////////
91
-
//Dropping function if it already exists
92
-
$tsql1 = "IF OBJECT_ID(N'dbo.ifGetTotalItems', N'IF') IS NOT NULL DROP FUNCTION dbo.ifGetTotalItems;";
93
-
$getProducts = sqlsrv_query($conn, $tsql1);
94
-
//Error handling
95
-
if ($getProducts == FALSE)
96
-
{
97
-
echo"Error deleting the UDF";
98
-
die(FormatErrors(sqlsrv_errors()));
99
-
}
100
-
$tsql1 = "CREATE FUNCTION dbo.ifGetTotalItems (@OrderID INT) RETURNS TABLE WITH SCHEMABINDING AS RETURN (SELECT SUM(OrderQty) AS TotalItems FROM SalesLT.SalesOrderDetail WHERE SalesOrderID = @OrderID GROUP BY SalesOrderID);";
101
-
$getProducts = sqlsrv_query($conn, $tsql1);
102
-
//Error handling
103
-
if ($getProducts == FALSE)
104
-
{
105
-
echo"Error creating the UDF";
106
-
die(FormatErrors(sqlsrv_errors()));
107
-
}
108
-
$tsql1 = "SELECT s.SalesOrderID, s.OrderDate, s.CustomerID, f.TotalItems FROM SalesLT.SalesOrderHeader s CROSS APPLY dbo.ifGetTotalItems(s.SalesOrderID) f ORDER BY SalesOrderID;";
109
-
$getProducts = sqlsrv_query($conn, $tsql1);
110
-
//Error handling
111
-
if ($getProducts == FALSE)
112
-
{
113
-
echo"Error executing the UDF";
114
-
die(FormatErrors(sqlsrv_errors()));
115
-
}
116
-
$productCount = 0;
117
-
$ctr = 0;
118
-
?>
119
-
<h1> First 10 results are after executing a query that uses the UDF: </h1>
89
+
//////////////////UDF/////////////////////////
90
+
//Dropping function if it already exists
91
+
$tsql1 = "IF OBJECT_ID(N'dbo.ifGetTotalItems', N'IF') IS NOT NULL DROP FUNCTION dbo.ifGetTotalItems;";
92
+
$getProducts = sqlsrv_query($conn, $tsql1);
93
+
//Error handling
94
+
if ($getProducts == false) {
95
+
echo"Error deleting the UDF";
96
+
die(FormatErrors(sqlsrv_errors()));
97
+
}
98
+
$tsql1 = "CREATE FUNCTION dbo.ifGetTotalItems (@OrderID INT) RETURNS TABLE WITH SCHEMABINDING AS RETURN (SELECT SUM(OrderQty) AS TotalItems FROM SalesLT.SalesOrderDetail WHERE SalesOrderID = @OrderID GROUP BY SalesOrderID);";
99
+
$getProducts = sqlsrv_query($conn, $tsql1);
100
+
//Error handling
101
+
if ($getProducts == false) {
102
+
echo"Error creating the UDF";
103
+
die(FormatErrors(sqlsrv_errors()));
104
+
}
105
+
$tsql1 = "SELECT s.SalesOrderID, s.OrderDate, s.CustomerID, f.TotalItems FROM SalesLT.SalesOrderHeader s CROSS APPLY dbo.ifGetTotalItems(s.SalesOrderID) f ORDER BY SalesOrderID;";
106
+
$getProducts = sqlsrv_query($conn, $tsql1);
107
+
//Error handling
108
+
if ($getProducts == false) {
109
+
echo"Error executing the UDF";
110
+
die(FormatErrors(sqlsrv_errors()));
111
+
}
112
+
$productCount = 0;
113
+
$ctr = 0;
114
+
?>
115
+
<h1> First 10 results are after executing a query that uses the UDF: </h1>
0 commit comments