Changed sample code to adhere to PSR standard (#887)
This commit is contained in:
parent
b2a195001e
commit
8e6c181c59
|
@ -24,16 +24,16 @@
|
|||
<h1> First 10 results are : </h1>
|
||||
|
||||
<?php
|
||||
while($row = $getProducts->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
if($ctr>9)
|
||||
while ($row = $getProducts->fetch(PDO::FETCH_ASSOC)) {
|
||||
if ($ctr>9) {
|
||||
break;
|
||||
}
|
||||
$ctr++;
|
||||
echo($row['CompanyName']);
|
||||
echo("<br/>");
|
||||
$productCount++;
|
||||
}
|
||||
$getProducts = NULL;
|
||||
$getProducts = null;
|
||||
|
||||
$tsql = "INSERT INTO SalesLT.Product (Name, ProductNumber, StandardCost, ListPrice, SellStartDate) OUTPUT INSERTED.* VALUES ('SQL New 1', 'SQL New 2', 0, 0, getdate())";
|
||||
|
||||
|
@ -45,11 +45,10 @@
|
|||
<h1> Product Key inserted is :</h1>
|
||||
|
||||
<?php
|
||||
while($row = $insertReview->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
while ($row = $insertReview->fetch(PDO::FETCH_ASSOC)) {
|
||||
echo($row['ProductID']."<br/>");
|
||||
}
|
||||
$insertReview = NULL;
|
||||
$insertReview = null;
|
||||
|
||||
//Delete Query
|
||||
//We are deleting the same record
|
||||
|
|
|
@ -10,17 +10,18 @@
|
|||
//Executes the query
|
||||
$getProducts = sqlsrv_query($conn, $tsql);
|
||||
//Error handling
|
||||
if ($getProducts == FALSE)
|
||||
if ($getProducts == false) {
|
||||
die(FormatErrors(sqlsrv_errors()));
|
||||
}
|
||||
$productCount = 0;
|
||||
$ctr = 0;
|
||||
?>
|
||||
<h1> First 10 results are : </h1>
|
||||
<?php
|
||||
while($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC))
|
||||
{
|
||||
if($ctr>9)
|
||||
while ($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC)) {
|
||||
if ($ctr>9) {
|
||||
break;
|
||||
}
|
||||
$ctr++;
|
||||
echo($row['CompanyName']);
|
||||
echo("<br/>");
|
||||
|
@ -31,13 +32,13 @@
|
|||
$tsql = "INSERT INTO SalesLT.Product (Name, ProductNumber, StandardCost, ListPrice, SellStartDate) OUTPUT INSERTED.ProductID VALUES ('SQL New 1', 'SQL New 2', 0, 0, getdate())";
|
||||
//Insert query
|
||||
$insertReview = sqlsrv_query($conn, $tsql);
|
||||
if($insertReview == FALSE)
|
||||
if ($insertReview == false) {
|
||||
die(FormatErrors(sqlsrv_errors()));
|
||||
}
|
||||
?>
|
||||
<h1> Product Key inserted is :</h1>
|
||||
<?php
|
||||
while($row = sqlsrv_fetch_array($insertReview, SQLSRV_FETCH_ASSOC))
|
||||
{
|
||||
while ($row = sqlsrv_fetch_array($insertReview, SQLSRV_FETCH_ASSOC)) {
|
||||
echo($row['ProductID']);
|
||||
}
|
||||
sqlsrv_free_stmt($insertReview);
|
||||
|
@ -47,19 +48,20 @@
|
|||
$params = array("SQL New 1");
|
||||
|
||||
$deleteReview = sqlsrv_prepare($conn, $tsql, $params);
|
||||
if($deleteReview == FALSE)
|
||||
if ($deleteReview == false) {
|
||||
die(FormatErrors(sqlsrv_errors()));
|
||||
}
|
||||
|
||||
if(sqlsrv_execute($deleteReview) == FALSE)
|
||||
if (sqlsrv_execute($deleteReview) == false) {
|
||||
die(FormatErrors(sqlsrv_errors()));
|
||||
}
|
||||
|
||||
function FormatErrors($errors)
|
||||
{
|
||||
/* Display errors. */
|
||||
echo "Error information: <br/>";
|
||||
|
||||
foreach ( $errors as $error )
|
||||
{
|
||||
foreach ($errors as $error) {
|
||||
echo "SQLSTATE: ".$error['SQLSTATE']."<br/>";
|
||||
echo "Code: ".$error['code']."<br/>";
|
||||
echo "Message: ".$error['message']."<br/>";
|
||||
|
|
Loading…
Reference in a new issue