Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fc94edc
Modernize and clean up cod examples
ravage84 Apr 23, 2020
7de89ff
Add editorconfig file to assist supporting IDEs in formatting PHP & B…
ravage84 Apr 23, 2020
a0001dd
Ignore Composer's vendor folder
ravage84 Apr 23, 2020
a4f492a
Add Composer file and add PHPCS as dev dependency
ravage84 Apr 23, 2020
0ccfd6e
Add PHPCS config file with PSR-2 as base code style standard & some more
ravage84 Apr 23, 2020
b45d14f
Add Composer scripts to execute code style check & fix through PHPCS
ravage84 Apr 23, 2020
5437b46
Automatic Code style fixes through PHPCS' PHP Code Beautifier
ravage84 Apr 23, 2020
04e3f27
Do no use logical operator "or", use "||" instead
ravage84 Apr 23, 2020
bc6e125
Disable code style sniff on "Side Effects"
ravage84 Apr 23, 2020
cc8c554
Spread strings longer than allowed over multiple lines
ravage84 Apr 23, 2020
33c7a03
Add spacing in comments to improve readability
ravage84 Apr 23, 2020
9387ed0
Replace non-standard use of comment sign with official multi line com…
ravage84 Apr 23, 2020
093fbf5
Method naming in camel case
ravage84 Apr 23, 2020
739c924
Variable names in camel case
ravage84 Apr 23, 2020
3dde4da
Do not use double quotes where not necessary
ravage84 Apr 23, 2020
86fb545
Use strict comparison operator
ravage84 Apr 23, 2020
f743e52
function naming in snake case
ravage84 Apr 23, 2020
56ac53d
Do not use non-existing return value of void function
ravage84 Apr 23, 2020
120805f
Fix typos
ravage84 Apr 23, 2020
5b3b63e
Make more placeholder strings more readable by using snake case
ravage84 Apr 23, 2020
a6f5c9f
Use sprintf() instead of long concatenation
ravage84 Apr 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*.php]
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.bat]
end_of_line = crlf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,6 @@ samples/features/sql-management-objects/src/out/CodeCoverage/CodeCoverage.config
# Certificates
*.pem
*.p12

# Composer
/vendor/
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "microsoft/sql-server-samples",
"description": "Official Microsoft GitHub Repository containing code samples for SQL Server",
"type": "project",
"require": {
"php": ">=7.0.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5"
},
"license": "MIT",
"minimum-stability": "stable",
"scripts": {
"cs-check": "phpcs -p --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1",
"cs-fix": "phpcbf -p --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1"
}
}
72 changes: 72 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0"?>
<ruleset name="MS SQL Server Examples">
<description>The coding standard for MS SQL Server PHP Examples.</description>

<!-- Folders & files to be checked -->
<file>samples/tutorials/php</file>

<!-- File extensions to be checked -->
<arg name="extensions" value="php"/>

<!-- PSR-2 base standard -->
<rule ref="PSR2"/>

<!-- Disable code style sniff on side effects -->
<rule ref="PSR1">
<exclude name="PSR1.Files.SideEffects"/>
</rule>

<!-- General sniffs -->
<rule ref="Generic.Files.LineLength"/>
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Commenting.FunctionCommentThrowTag"/>
<rule ref="Squiz.Classes.LowercaseClassKeywords"/>
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
<rule ref="Generic.Formatting.NoSpaceAfterCast"/>
<rule ref="Squiz.Operators.ValidLogicalOperators"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops"/>
<rule ref="Squiz.PHP.Eval"/>
<rule ref="Generic.PHP.ForbiddenFunctions"/>
<rule ref="Squiz.PHP.NonExecutableCode"/>
<rule ref="Squiz.Classes.ClassFileName"/>
<rule ref="Squiz.Scope.MemberVarScope"/>
<rule ref="Squiz.Scope.StaticThisUsage"/>
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>

</ruleset>
Original file line number Diff line number Diff line change
@@ -1,63 +1,68 @@
<?php
echo "\n";
$serverName = "tcp:yourserver.database.windows.net,1433";

$connectionOptions = array("Database"=>"yourpassword",
"Uid"=>"yourusername", "PWD"=>"yourpassword");

$conn = sqlsrv_connect($serverName, $connectionOptions);

$tsql = "SELECT [CompanyName] FROM SalesLT.Customer";

$getProducts = sqlsrv_query($conn, $tsql);

if ($getProducts == FALSE)
die(FormatErrors(sqlsrv_errors()));

$productCount = 0;
$ctr = 0;
while($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC))
{
$ctr++;
echo($row['CompanyName']);
echo("<br/>");
$productCount++;
if($ctr>10)
break;
}

sqlsrv_free_stmt($getProducts);

$tsql = "INSERT SalesLT.Product (Name, ProductNumber, StandardCost, ListPrice, SellStartDate) OUTPUT INSERTED.ProductID VALUES ('SQL Server 15', 'SQL Server 12', 0, 0, getdate())";


$insertReview = sqlsrv_query($conn, $tsql);
if($insertReview == FALSE)
die(FormatErrors( sqlsrv_errors()));


while($row = sqlsrv_fetch_array($insertReview, SQLSRV_FETCH_ASSOC))
{
echo($row['ProductID']);
}
sqlsrv_free_stmt($insertReview);

$tsql = "DELETE FROM [SalesLT].[Product] WHERE Name=?";
$params = array("SQL Server 15");

$deleteReview = sqlsrv_prepare($conn, $tsql, $params);
if($deleteReview == FALSE)
die(FormatErrors(sqlsrv_errors()));

if(sqlsrv_execute($deleteReview) == FALSE)
die(FormatErrors(sqlsrv_errors()));

while($row = sqlsrv_fetch_array($deleteReview, SQLSRV_FETCH_ASSOC))
{
echo($row['ProductID']);
}
sqlsrv_free_stmt($deleteReview);


?>

echo "\n";
$serverName = 'tcp:your_server.database.windows.net,1433';

$connectionOptions = [
'Database' => 'your_database',
'Uid' => 'your_username',
'PWD' => 'your_password',
];

$conn = sqlsrv_connect($serverName, $connectionOptions);

$tsql = 'SELECT [CompanyName] FROM SalesLT.Customer';

$getProducts = sqlsrv_query($conn, $tsql);

if ($getProducts === false) {
format_errors(sqlsrv_errors());
die();
}

$productCount = 0;
$ctr = 0;
while ($row = sqlsrv_fetch_array($getProducts, SQLSRV_FETCH_ASSOC)) {
$ctr++;
echo($row['CompanyName']);
echo('<br/>');
$productCount++;
if ($ctr > 10) {
break;
}
}

sqlsrv_free_stmt($getProducts);

$tsql = "INSERT SalesLT.Product (Name, ProductNumber, StandardCost, ListPrice, SellStartDate)
OUTPUT INSERTED.ProductID
VALUES ('SQL Server 15', 'SQL Server 12', 0, 0, getdate());";

$insertReview = sqlsrv_query($conn, $tsql);
if ($insertReview === false) {
format_errors(sqlsrv_errors());
die();
}

while ($row = sqlsrv_fetch_array($insertReview, SQLSRV_FETCH_ASSOC)) {
echo($row['ProductID']);
}
sqlsrv_free_stmt($insertReview);

$tsql = 'DELETE FROM [SalesLT].[Product] WHERE Name=?';
$params = ['SQL Server 15'];

$deleteReview = sqlsrv_prepare($conn, $tsql, $params);
if ($deleteReview === false) {
format_errors(sqlsrv_errors());
die();
}

if (sqlsrv_execute($deleteReview) === false) {
format_errors(sqlsrv_errors());
die();
}

while ($row = sqlsrv_fetch_array($deleteReview, SQLSRV_FETCH_ASSOC)) {
echo($row['ProductID']);
}
sqlsrv_free_stmt($deleteReview);
Loading