Add spacing in comments to improve readability

This commit is contained in:
Marc Würth
2020-04-23 21:50:31 +02:00
parent cc8c554a55
commit 33c7a030d8
9 changed files with 35 additions and 35 deletions
@@ -5,9 +5,9 @@ $connectionOptions = [
"Uid" => "yourusername", "Uid" => "yourusername",
"PWD" => "yourpassword", "PWD" => "yourpassword",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
//////////////////STORED PROCEDURE///////////////////////// ////////////////// STORED PROCEDURE /////////////////////////
$tsql = "CREATE PROCEDURE sp_GetCompanies22 AS BEGIN SELECT [CompanyName] FROM SalesLT.Customer END"; $tsql = "CREATE PROCEDURE sp_GetCompanies22 AS BEGIN SELECT [CompanyName] FROM SalesLT.Customer END";
$storedProc = sqlsrv_query($conn, $tsql); $storedProc = sqlsrv_query($conn, $tsql);
if ($storedProc == false) { if ($storedProc == false) {
@@ -17,9 +17,9 @@ if ($storedProc == false) {
sqlsrv_free_stmt($storedProc); sqlsrv_free_stmt($storedProc);
$tsql = "exec sp_GETCompanies22"; $tsql = "exec sp_GETCompanies22";
//Executes the query // Executes the query
$getProducts = sqlsrv_query($conn, $tsql); $getProducts = sqlsrv_query($conn, $tsql);
//Error handling // Error handling
if ($getProducts == false) { if ($getProducts == false) {
echo "Error executing Stored Procedure"; echo "Error executing Stored Procedure";
die(FormatErrors(sqlsrv_errors())); die(FormatErrors(sqlsrv_errors()));
@@ -30,7 +30,7 @@ $ctr = 0;
<h1> First 10 results are after executing the stored procedure: </h1> <h1> First 10 results are after executing the stored procedure: </h1>
<?php <?php
while ($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC)) { while ($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC)) {
//Printing only the first 10 results // Printing only the first 10 results
if ($ctr > 9) { if ($ctr > 9) {
break; break;
} }
@@ -50,7 +50,7 @@ if ($storedProc == false) {
sqlsrv_free_stmt($storedProc); sqlsrv_free_stmt($storedProc);
?> ?>
<?php <?php
//////////////////TRANSACTION///////////////////////// ////////////////// TRANSACTION /////////////////////////
if (sqlsrv_begin_transaction($conn) == false) { if (sqlsrv_begin_transaction($conn) == false) {
echo "Error opening connection"; echo "Error opening connection";
die(FormatErrors(sqlsrv_errors())); die(FormatErrors(sqlsrv_errors()));
@@ -85,11 +85,11 @@ sqlsrv_free_stmt($stmt2);
?> ?>
<?php <?php
//////////////////UDF///////////////////////// ////////////////// UDF /////////////////////////
//Dropping function if it already exists // Dropping function if it already exists
$tsql1 = "IF OBJECT_ID(N'dbo.ifGetTotalItems', N'IF') IS NOT NULL DROP FUNCTION dbo.ifGetTotalItems;"; $tsql1 = "IF OBJECT_ID(N'dbo.ifGetTotalItems', N'IF') IS NOT NULL DROP FUNCTION dbo.ifGetTotalItems;";
$getProducts = sqlsrv_query($conn, $tsql1); $getProducts = sqlsrv_query($conn, $tsql1);
//Error handling // Error handling
if ($getProducts == false) { if ($getProducts == false) {
echo "Error deleting the UDF"; echo "Error deleting the UDF";
die(FormatErrors(sqlsrv_errors())); die(FormatErrors(sqlsrv_errors()));
@@ -100,7 +100,7 @@ $tsql1 = 'CREATE FUNCTION dbo.ifGetTotalItems (@OrderID INT) RETURNS TABLE WITH
GROUP BY SalesOrderID GROUP BY SalesOrderID
);'; );';
$getProducts = sqlsrv_query($conn, $tsql1); $getProducts = sqlsrv_query($conn, $tsql1);
//Error handling // Error handling
if ($getProducts == false) { if ($getProducts == false) {
echo "Error creating the UDF"; echo "Error creating the UDF";
die(FormatErrors(sqlsrv_errors())); die(FormatErrors(sqlsrv_errors()));
@@ -110,7 +110,7 @@ FROM SalesLT.SalesOrderHeader s
CROSS APPLY dbo.ifGetTotalItems(s.SalesOrderID) f CROSS APPLY dbo.ifGetTotalItems(s.SalesOrderID) f
ORDER BY SalesOrderID;"; ORDER BY SalesOrderID;";
$getProducts = sqlsrv_query($conn, $tsql1); $getProducts = sqlsrv_query($conn, $tsql1);
//Error handling // Error handling
if ($getProducts == false) { if ($getProducts == false) {
echo "Error executing the UDF"; echo "Error executing the UDF";
die(FormatErrors(sqlsrv_errors())); die(FormatErrors(sqlsrv_errors()));
@@ -124,7 +124,7 @@ echo "SalesOrderID CustomerID TotalItems";
echo("<br/>"); echo("<br/>");
while ($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC)) { while ($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC)) {
//Printing only the top 10 results // Printing only the top 10 results
if ($ctr > 9) { if ($ctr > 9) {
break; break;
} }
@@ -7,10 +7,10 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
//Read Query // Read Query
$tsql = "SELECT SUM(Price) as sum FROM Table_with_5M_rows"; $tsql = "SELECT SUM(Price) as sum FROM Table_with_5M_rows";
$getResults = sqlsrv_query($conn, $tsql); $getResults = sqlsrv_query($conn, $tsql);
echo("Sum: "); echo("Sum: ");
@@ -5,7 +5,7 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn) { if ($conn) {
echo "Connected!"; echo "Connected!";
@@ -5,10 +5,10 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
//Insert Query // Insert Query
echo("Inserting a new row into table" . PHP_EOL); echo("Inserting a new row into table" . PHP_EOL);
$tsql = "INSERT INTO TestSchema.Employees (Name, Location) VALUES (?,?);"; $tsql = "INSERT INTO TestSchema.Employees (Name, Location) VALUES (?,?);";
$params = ['Jake', 'United States']; $params = ['Jake', 'United States'];
@@ -21,7 +21,7 @@ echo($rowsAffected . " row(s) inserted: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Update Query // Update Query
$userToUpdate = 'Nikita'; $userToUpdate = 'Nikita';
$tsql = "UPDATE TestSchema.Employees SET Location = ? WHERE Name = ?"; $tsql = "UPDATE TestSchema.Employees SET Location = ? WHERE Name = ?";
@@ -36,7 +36,7 @@ if ($getResults == false || $rowsAffected == false) {
echo($rowsAffected . " row(s) updated: " . PHP_EOL); echo($rowsAffected . " row(s) updated: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Delte Query // Delte Query
$userToDelete = 'Jared'; $userToDelete = 'Jared';
$tsql = "DELETE FROM TestSchema.Employees WHERE Name = ?"; $tsql = "DELETE FROM TestSchema.Employees WHERE Name = ?";
$params = [$userToDelete]; $params = [$userToDelete];
@@ -49,7 +49,7 @@ if ($getResults == false || $rowsAffected == false) {
echo($rowsAffected . " row(s) deleted: " . PHP_EOL); echo($rowsAffected . " row(s) deleted: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Read Query // Read Query
$tsql = "SELECT Id, Name, Location FROM TestSchema.Employees;"; $tsql = "SELECT Id, Name, Location FROM TestSchema.Employees;";
$getResults = sqlsrv_query($conn, $tsql); $getResults = sqlsrv_query($conn, $tsql);
echo("Reading data from table" . PHP_EOL); echo("Reading data from table" . PHP_EOL);
@@ -7,10 +7,10 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
//Read Query // Read Query
$tsql = "SELECT SUM(Price) as sum FROM Table_with_5M_rows"; $tsql = "SELECT SUM(Price) as sum FROM Table_with_5M_rows";
$getResults = sqlsrv_query($conn, $tsql); $getResults = sqlsrv_query($conn, $tsql);
echo("Sum: "); echo("Sum: ");
@@ -5,10 +5,10 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
//Insert Query // Insert Query
echo("Inserting a new row into table" . PHP_EOL); echo("Inserting a new row into table" . PHP_EOL);
$tsql = "INSERT INTO TestSchema.Employees (Name, Location) VALUES (?,?);"; $tsql = "INSERT INTO TestSchema.Employees (Name, Location) VALUES (?,?);";
$params = ['Jake', 'United States']; $params = ['Jake', 'United States'];
@@ -21,7 +21,7 @@ echo($rowsAffected . " row(s) inserted: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Update Query // Update Query
$userToUpdate = 'Nikita'; $userToUpdate = 'Nikita';
$tsql = "UPDATE TestSchema.Employees SET Location = ? WHERE Name = ?"; $tsql = "UPDATE TestSchema.Employees SET Location = ? WHERE Name = ?";
@@ -36,7 +36,7 @@ if ($getResults == false || $rowsAffected == false) {
echo($rowsAffected . " row(s) updated: " . PHP_EOL); echo($rowsAffected . " row(s) updated: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Delte Query // Delte Query
$userToDelete = 'Jared'; $userToDelete = 'Jared';
$tsql = "DELETE FROM TestSchema.Employees WHERE Name = ?"; $tsql = "DELETE FROM TestSchema.Employees WHERE Name = ?";
$params = [$userToDelete]; $params = [$userToDelete];
@@ -49,7 +49,7 @@ if ($getResults == false || $rowsAffected == false) {
echo($rowsAffected . " row(s) deleted: " . PHP_EOL); echo($rowsAffected . " row(s) deleted: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Read Query // Read Query
$tsql = "SELECT Id, Name, Location FROM TestSchema.Employees;"; $tsql = "SELECT Id, Name, Location FROM TestSchema.Employees;";
$getResults = sqlsrv_query($conn, $tsql); $getResults = sqlsrv_query($conn, $tsql);
echo("Reading data from table" . PHP_EOL); echo("Reading data from table" . PHP_EOL);
@@ -7,10 +7,10 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
//Read Query // Read Query
$tsql = "SELECT SUM(Price) as sum FROM Table_with_5M_rows"; $tsql = "SELECT SUM(Price) as sum FROM Table_with_5M_rows";
$getResults = sqlsrv_query($conn, $tsql); $getResults = sqlsrv_query($conn, $tsql);
echo("Sum: "); echo("Sum: ");
@@ -5,7 +5,7 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn) { if ($conn) {
echo "Connected!"; echo "Connected!";
@@ -5,10 +5,10 @@ $connectionOptions = [
"Uid" => "sa", "Uid" => "sa",
"PWD" => "your_password", "PWD" => "your_password",
]; ];
//Establishes the connection // Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions); $conn = sqlsrv_connect($serverName, $connectionOptions);
//Insert Query // Insert Query
echo("Inserting a new row into table" . PHP_EOL); echo("Inserting a new row into table" . PHP_EOL);
$tsql = "INSERT INTO TestSchema.Employees (Name, Location) VALUES (?,?);"; $tsql = "INSERT INTO TestSchema.Employees (Name, Location) VALUES (?,?);";
$params = ['Jake', 'United States']; $params = ['Jake', 'United States'];
@@ -21,7 +21,7 @@ echo($rowsAffected . " row(s) inserted: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Update Query // Update Query
$userToUpdate = 'Nikita'; $userToUpdate = 'Nikita';
$tsql = "UPDATE TestSchema.Employees SET Location = ? WHERE Name = ?"; $tsql = "UPDATE TestSchema.Employees SET Location = ? WHERE Name = ?";
@@ -36,7 +36,7 @@ if ($getResults == false || $rowsAffected == false) {
echo($rowsAffected . " row(s) updated: " . PHP_EOL); echo($rowsAffected . " row(s) updated: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Delete Query // Delete Query
$userToDelete = 'Jared'; $userToDelete = 'Jared';
$tsql = "DELETE FROM TestSchema.Employees WHERE Name = ?"; $tsql = "DELETE FROM TestSchema.Employees WHERE Name = ?";
$params = [$userToDelete]; $params = [$userToDelete];
@@ -49,7 +49,7 @@ if ($getResults == false || $rowsAffected == false) {
echo($rowsAffected . " row(s) deleted: " . PHP_EOL); echo($rowsAffected . " row(s) deleted: " . PHP_EOL);
sqlsrv_free_stmt($getResults); sqlsrv_free_stmt($getResults);
//Read Query // Read Query
$tsql = "SELECT Id, Name, Location FROM TestSchema.Employees;"; $tsql = "SELECT Id, Name, Location FROM TestSchema.Employees;";
$getResults = sqlsrv_query($conn, $tsql); $getResults = sqlsrv_query($conn, $tsql);
echo("Reading data from table" . PHP_EOL); echo("Reading data from table" . PHP_EOL);