SlideShare a Scribd company logo
Example #1 sqlsrv_begin_transaction() example
<?php
$serverName = "serverNamesqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}

/* Begin the transaction. */
if ( sqlsrv_begin_transaction( $conn ) === false ) {
die( print_r( sqlsrv_errors(), true ));
}

/* Initialize parameter values. */
$orderId = 1; $qty = 10; $productId = 100;

/* Set up and execute the first query. */
$sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID)
VALUES (?, ?, ?)";
$params1 = array( $orderId, $qty, $productId );
$stmt1 = sqlsrv_query( $conn, $sql1, $params1 );

/* Set up and execute the second query. */
$sql2 = "UPDATE InventoryTable
SET Quantity = (Quantity - ?)
WHERE ProductID = ?";
$params2 = array($qty, $productId);
$stmt2 = sqlsrv_query( $conn, $sql2, $params2 );

/* If both queries were successful, commit the transaction. */
/* Otherwise, rollback the transaction. */
if( $stmt1 && $stmt2 ) {
sqlsrv_commit( $conn );
echo "Transaction committed.<br />";
} else {
sqlsrv_rollback( $conn );
echo "Transaction rolled back.<br />";
}
?>
Description ¶
bool sqlsrv_cancel ( resource $stmt )
Example #1 sqlsrv_cancel() example
<?php
$serverName = "serverNamesqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}

$sql = "SELECT Sales FROM Table_1";

$stmt = sqlsrv_prepare( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}

if( sqlsrv_execute( $stmt ) === false) {
die( print_r( sqlsrv_errors(), true));
}

$salesTotal = 0;
$count = 0;

while( ($row = sqlsrv_fetch_array( $stmt)) && $salesTotal <=100000)
{
$qty = $row[0];
$price = $row[1];
$salesTotal += ( $price * $qty);
$count++;
}

echo "$count sales accounted for the first $$salesTotal in revenue.<br />";

// Cancel the pending results. The statement can be reused.
sqlsrv_cancel( $stmt);
?>
Description ¶
array sqlsrv_client_info ( resource $conn )
Example #1 sqlsrv_client_info() example
<?php
$serverName = "serverNamesqlexpress";
$connOptions = array("UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connOptions );

if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}

if( $client_info = sqlsrv_client_info( $conn)) {
foreach( $client_info as $key => $value) {
echo $key.": ".$value."<br />";
}
} else {
echo "Error in retrieving client info.<br />";
}
?>
Description ¶
bool sqlsrv_close ( resource $conn )
Example #1 sqlsrv_close() example
<?php
$serverName = "serverNamesqlexpres";
$connOptions = array("UID"=>"username", "PWD"=>"password", "Database"=>"dbname");
$conn = sqlsrv_connect( $serverName, $connOptions );
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}

//------------------------------------// Perform database operations here.
//-------------------------------------

// Close the connection.
sqlsrv_close( $conn );
?>
Description ¶
bool sqlsrv_commit ( resource $conn )
Example #1 sqlsrv_commit() example
<?php
$serverName = "serverNamesqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}

/* Begin the transaction. */
if ( sqlsrv_begin_transaction( $conn ) === false ) {
die( print_r( sqlsrv_errors(), true ));
}

/* Initialize parameter values. */
$orderId = 1; $qty = 10; $productId = 100;
/* Set up and execute the first query. */
$sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID)
VALUES (?, ?, ?)";
$params1 = array( $orderId, $qty, $productId );
$stmt1 = sqlsrv_query( $conn, $sql1, $params1 );

/* Set up and execute the second query. */
$sql2 = "UPDATE InventoryTable
SET Quantity = (Quantity - ?)
WHERE ProductID = ?";
$params2 = array($qty, $productId);
$stmt2 = sqlsrv_query( $conn, $sql2, $params2 );

/* If both queries were successful, commit the transaction. */
/* Otherwise, rollback the transaction. */
if( $stmt1 && $stmt2 ) {
sqlsrv_commit( $conn );
echo "Transaction committed.<br />";
} else {
sqlsrv_rollback( $conn );
echo "Transaction rolled back.<br />";
}
?>
Description ¶
bool sqlsrv_configure ( string $setting , mixed $value )

More Related Content

What's hot (20)

DOCX
Php update and delet operation
syeda zoya mehdi
 
TXT
Gta v savegame
hozayfa999
 
TXT
Data20161007
capegmail
 
PDF
Command Bus To Awesome Town
Ross Tuck
 
PDF
R57shell
ady36
 
PDF
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
PDF
Your code sucks, let's fix it
Rafael Dohms
 
PDF
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon
 
PDF
Models and Service Layers, Hemoglobin and Hobgoblins
Ross Tuck
 
DOCX
Latihan form login
Edy Sinaga
 
PDF
Things I Believe Now That I'm Old
Ross Tuck
 
PPTX
Presentation1
Rahadyan Gusti
 
KEY
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
PPT
Mocking Dependencies in PHPUnit
mfrost503
 
PDF
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
Rafael Dohms
 
PPTX
Pm 4.0 permission_storage
Oleg K
 
PDF
Command-Oriented Architecture
Luiz Messias
 
PDF
Silex meets SOAP & REST
Hugo Hamon
 
PDF
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
Rafael Dohms
 
DOCX
Karan chanana
karan chanana
 
Php update and delet operation
syeda zoya mehdi
 
Gta v savegame
hozayfa999
 
Data20161007
capegmail
 
Command Bus To Awesome Town
Ross Tuck
 
R57shell
ady36
 
Pemrograman Web 8 - MySQL
Nur Fadli Utomo
 
Your code sucks, let's fix it
Rafael Dohms
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon
 
Models and Service Layers, Hemoglobin and Hobgoblins
Ross Tuck
 
Latihan form login
Edy Sinaga
 
Things I Believe Now That I'm Old
Ross Tuck
 
Presentation1
Rahadyan Gusti
 
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
Mocking Dependencies in PHPUnit
mfrost503
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
Rafael Dohms
 
Pm 4.0 permission_storage
Oleg K
 
Command-Oriented Architecture
Luiz Messias
 
Silex meets SOAP & REST
Hugo Hamon
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
Rafael Dohms
 
Karan chanana
karan chanana
 

Viewers also liked (20)

PPTX
Jquery
Kartin Yuliyanti
 
PPTX
Cloud computing
Kartin Yuliyanti
 
DOCX
Cheat gta
benny09
 
PDF
jaringan komputer - pengenalan
PutuMahendra Wijaya
 
DOCX
Cheat gta
Ahmad Zaini Mujahiddin
 
DOTX
Cheat gta san andreas ps2
Operator Warnet Vast Raha
 
DOC
basic error handling wesite
PutuMahendra Wijaya
 
DOCX
Cheat gta san andreas ps2
Operator Warnet Vast Raha
 
PDF
Analisa Sistem Informasi
PutuMahendra Wijaya
 
PPTX
Eucalipto
Andreita Amado Amado
 
PDF
Gabii
emalfredocastro
 
PDF
Síntesis confech
Caim Usach
 
PPTX
Niver joão pedro
momentosfamilia
 
PPTX
Diana amuy
dianaamuyo
 
DOCX
Roles evento profetico 2013
Bea Cross
 
PDF
Algebra guia a 3
Paula Altamirano Azúa
 
DOC
Plantilla ppa documento-v4.doc semana santa
Lucas Cabrera
 
PPTX
La velocidad [autoguardado]
andres1401
 
PDF
Politicas y propuestas de acción para el desarrollo de la educación chilena, ...
Caim Usach
 
Cloud computing
Kartin Yuliyanti
 
Cheat gta
benny09
 
jaringan komputer - pengenalan
PutuMahendra Wijaya
 
Cheat gta san andreas ps2
Operator Warnet Vast Raha
 
basic error handling wesite
PutuMahendra Wijaya
 
Cheat gta san andreas ps2
Operator Warnet Vast Raha
 
Analisa Sistem Informasi
PutuMahendra Wijaya
 
Síntesis confech
Caim Usach
 
Niver joão pedro
momentosfamilia
 
Diana amuy
dianaamuyo
 
Roles evento profetico 2013
Bea Cross
 
Algebra guia a 3
Paula Altamirano Azúa
 
Plantilla ppa documento-v4.doc semana santa
Lucas Cabrera
 
La velocidad [autoguardado]
andres1401
 
Politicas y propuestas de acción para el desarrollo de la educación chilena, ...
Caim Usach
 
Ad

Similar to Coding website (16)

PPTX
Week6
David Sherlock
 
PDF
PostgreSQL 9 Administration Cookbook - Second Edition Simon Riggs
mowwoiq538
 
PPTX
lecture 7 - Introduction to MySQL with PHP.pptx
AOmaAli
 
PPSX
Php session
argusacademy
 
PDF
PostgreSQL 9 Administration Cookbook - Second Edition Simon Riggs
bligesilva28
 
PPTX
PHP POSTGRESQL integration
Sandhya Sharma
 
PPT
Synapse india reviews on php and sql
saritasingh19866
 
PPTX
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 
PPTX
chapter_Seven Database manipulation using php.pptx
Getawu
 
PPT
Download It
webhostingguy
 
PDF
PHP with MySQL
wahidullah mudaser
 
PPTX
PHP on Windows and on Azure
Maarten Balliauw
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
PPT
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
PostgreSQL 9 Administration Cookbook - Second Edition Simon Riggs
mowwoiq538
 
lecture 7 - Introduction to MySQL with PHP.pptx
AOmaAli
 
Php session
argusacademy
 
PostgreSQL 9 Administration Cookbook - Second Edition Simon Riggs
bligesilva28
 
PHP POSTGRESQL integration
Sandhya Sharma
 
Synapse india reviews on php and sql
saritasingh19866
 
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 
chapter_Seven Database manipulation using php.pptx
Getawu
 
Download It
webhostingguy
 
PHP with MySQL
wahidullah mudaser
 
PHP on Windows and on Azure
Maarten Balliauw
 
Database Connectivity in PHP
Taha Malampatti
 
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Ad

More from PutuMahendra Wijaya (10)

PDF
Tugas pascal putu mahendra
PutuMahendra Wijaya
 
DOC
Makalah Manajemen Keuangan
PutuMahendra Wijaya
 
PDF
Proposal aq baru
PutuMahendra Wijaya
 
PDF
Cheat GTA PS 2
PutuMahendra Wijaya
 
PPT
Presentation msdm1.1
PutuMahendra Wijaya
 
PDF
Teknik reparasi pc dan monitor
PutuMahendra Wijaya
 
PDF
Panduan praktis belajar komputer
PutuMahendra Wijaya
 
DOCX
Fungsi vga onboard dan vga card
PutuMahendra Wijaya
 
PDF
Etika profesi & budi pekerti
PutuMahendra Wijaya
 
Tugas pascal putu mahendra
PutuMahendra Wijaya
 
Makalah Manajemen Keuangan
PutuMahendra Wijaya
 
Proposal aq baru
PutuMahendra Wijaya
 
Cheat GTA PS 2
PutuMahendra Wijaya
 
Presentation msdm1.1
PutuMahendra Wijaya
 
Teknik reparasi pc dan monitor
PutuMahendra Wijaya
 
Panduan praktis belajar komputer
PutuMahendra Wijaya
 
Fungsi vga onboard dan vga card
PutuMahendra Wijaya
 
Etika profesi & budi pekerti
PutuMahendra Wijaya
 

Coding website

  • 1. Example #1 sqlsrv_begin_transaction() example <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true )); } /* Begin the transaction. */ if ( sqlsrv_begin_transaction( $conn ) === false ) { die( print_r( sqlsrv_errors(), true )); } /* Initialize parameter values. */ $orderId = 1; $qty = 10; $productId = 100; /* Set up and execute the first query. */ $sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID) VALUES (?, ?, ?)"; $params1 = array( $orderId, $qty, $productId ); $stmt1 = sqlsrv_query( $conn, $sql1, $params1 ); /* Set up and execute the second query. */ $sql2 = "UPDATE InventoryTable SET Quantity = (Quantity - ?) WHERE ProductID = ?";
  • 2. $params2 = array($qty, $productId); $stmt2 = sqlsrv_query( $conn, $sql2, $params2 ); /* If both queries were successful, commit the transaction. */ /* Otherwise, rollback the transaction. */ if( $stmt1 && $stmt2 ) { sqlsrv_commit( $conn ); echo "Transaction committed.<br />"; } else { sqlsrv_rollback( $conn ); echo "Transaction rolled back.<br />"; } ?> Description ¶ bool sqlsrv_cancel ( resource $stmt ) Example #1 sqlsrv_cancel() example <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT Sales FROM Table_1"; $stmt = sqlsrv_prepare( $conn, $sql);
  • 3. if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } if( sqlsrv_execute( $stmt ) === false) { die( print_r( sqlsrv_errors(), true)); } $salesTotal = 0; $count = 0; while( ($row = sqlsrv_fetch_array( $stmt)) && $salesTotal <=100000) { $qty = $row[0]; $price = $row[1]; $salesTotal += ( $price * $qty); $count++; } echo "$count sales accounted for the first $$salesTotal in revenue.<br />"; // Cancel the pending results. The statement can be reused. sqlsrv_cancel( $stmt); ?> Description ¶ array sqlsrv_client_info ( resource $conn )
  • 4. Example #1 sqlsrv_client_info() example <?php $serverName = "serverNamesqlexpress"; $connOptions = array("UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connOptions ); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } if( $client_info = sqlsrv_client_info( $conn)) { foreach( $client_info as $key => $value) { echo $key.": ".$value."<br />"; } } else { echo "Error in retrieving client info.<br />"; } ?> Description ¶ bool sqlsrv_close ( resource $conn ) Example #1 sqlsrv_close() example <?php $serverName = "serverNamesqlexpres"; $connOptions = array("UID"=>"username", "PWD"=>"password", "Database"=>"dbname"); $conn = sqlsrv_connect( $serverName, $connOptions ); if( $conn === false ) { die( print_r( sqlsrv_errors(), true));
  • 5. } //------------------------------------// Perform database operations here. //------------------------------------- // Close the connection. sqlsrv_close( $conn ); ?> Description ¶ bool sqlsrv_commit ( resource $conn ) Example #1 sqlsrv_commit() example <?php $serverName = "serverNamesqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true )); } /* Begin the transaction. */ if ( sqlsrv_begin_transaction( $conn ) === false ) { die( print_r( sqlsrv_errors(), true )); } /* Initialize parameter values. */ $orderId = 1; $qty = 10; $productId = 100;
  • 6. /* Set up and execute the first query. */ $sql1 = "INSERT INTO OrdersTable (ID, Quantity, ProductID) VALUES (?, ?, ?)"; $params1 = array( $orderId, $qty, $productId ); $stmt1 = sqlsrv_query( $conn, $sql1, $params1 ); /* Set up and execute the second query. */ $sql2 = "UPDATE InventoryTable SET Quantity = (Quantity - ?) WHERE ProductID = ?"; $params2 = array($qty, $productId); $stmt2 = sqlsrv_query( $conn, $sql2, $params2 ); /* If both queries were successful, commit the transaction. */ /* Otherwise, rollback the transaction. */ if( $stmt1 && $stmt2 ) { sqlsrv_commit( $conn ); echo "Transaction committed.<br />"; } else { sqlsrv_rollback( $conn ); echo "Transaction rolled back.<br />"; } ?> Description ¶ bool sqlsrv_configure ( string $setting , mixed $value )