SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
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 )

Mais conteúdo relacionado

Mais procurados

R57shell
R57shellR57shell
R57shell
ady36
 

Mais procurados (20)

Php update and delet operation
Php update and delet operationPhp update and delet operation
Php update and delet operation
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegame
 
Data20161007
Data20161007Data20161007
Data20161007
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
R57shell
R57shellR57shell
R57shell
 
Pemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQLPemrograman Web 8 - MySQL
Pemrograman Web 8 - MySQL
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Latihan form login
Latihan form loginLatihan form login
Latihan form login
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
 
Presentation1
Presentation1Presentation1
Presentation1
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
 
Pm 4.0 permission_storage
Pm 4.0 permission_storagePm 4.0 permission_storage
Pm 4.0 permission_storage
 
Command-Oriented Architecture
Command-Oriented ArchitectureCommand-Oriented Architecture
Command-Oriented Architecture
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
 
Karan chanana
Karan chananaKaran chanana
Karan chanana
 

Destaque (20)

Projeto
ProjetoProjeto
Projeto
 
Jquery
JqueryJquery
Jquery
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Cheat gta
Cheat gtaCheat gta
Cheat gta
 
jaringan komputer - pengenalan
jaringan komputer - pengenalanjaringan komputer - pengenalan
jaringan komputer - pengenalan
 
Cheat gta
Cheat gtaCheat gta
Cheat gta
 
Cheat gta san andreas ps2
Cheat gta san andreas ps2Cheat gta san andreas ps2
Cheat gta san andreas ps2
 
basic error handling wesite
basic error handling wesitebasic error handling wesite
basic error handling wesite
 
Cheat gta san andreas ps2
Cheat gta san andreas ps2Cheat gta san andreas ps2
Cheat gta san andreas ps2
 
Analisa Sistem Informasi
Analisa Sistem InformasiAnalisa Sistem Informasi
Analisa Sistem Informasi
 
Eucalipto
EucaliptoEucalipto
Eucalipto
 
Gabii
GabiiGabii
Gabii
 
Síntesis confech
Síntesis confechSíntesis confech
Síntesis confech
 
Niver joão pedro
Niver joão pedroNiver joão pedro
Niver joão pedro
 
Diana amuy
Diana amuyDiana amuy
Diana amuy
 
Roles evento profetico 2013
Roles evento profetico 2013Roles evento profetico 2013
Roles evento profetico 2013
 
Algebra guia a 3
Algebra guia a 3Algebra guia a 3
Algebra guia a 3
 
Plantilla ppa documento-v4.doc semana santa
Plantilla ppa documento-v4.doc semana santaPlantilla ppa documento-v4.doc semana santa
Plantilla ppa documento-v4.doc semana santa
 
La velocidad [autoguardado]
La velocidad [autoguardado]La velocidad [autoguardado]
La velocidad [autoguardado]
 
Politicas y propuestas de acción para el desarrollo de la educación chilena, ...
Politicas y propuestas de acción para el desarrollo de la educación chilena, ...Politicas y propuestas de acción para el desarrollo de la educación chilena, ...
Politicas y propuestas de acción para el desarrollo de la educación chilena, ...
 

Semelhante a Coding website

Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
jhchabran
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
Taras Kalapun
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quiz
hnyb1002
 

Semelhante a Coding website (20)

Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Database Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and MysqlDatabase Management - Lecture 4 - PHP and Mysql
Database Management - Lecture 4 - PHP and Mysql
 
php plus mysql
php plus mysqlphp plus mysql
php plus mysql
 
Drush. Secrets come out.
Drush. Secrets come out.Drush. Secrets come out.
Drush. Secrets come out.
 
Php.docx
Php.docxPhp.docx
Php.docx
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Daily notes
Daily notesDaily notes
Daily notes
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Everything About PowerShell
Everything About PowerShellEverything About PowerShell
Everything About PowerShell
 
Php
PhpPhp
Php
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
Stored Procedure
Stored ProcedureStored Procedure
Stored Procedure
 
Database api
Database apiDatabase api
Database api
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
SQL so close I can paste it (YAPC::NA::2011 lightning talk)
SQL so close I can paste it (YAPC::NA::2011 lightning talk)SQL so close I can paste it (YAPC::NA::2011 lightning talk)
SQL so close I can paste it (YAPC::NA::2011 lightning talk)
 
Mysql & Php
Mysql & PhpMysql & Php
Mysql & Php
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quiz
 

Mais de PutuMahendra Wijaya (10)

Tugas pascal putu mahendra
Tugas pascal putu mahendraTugas pascal putu mahendra
Tugas pascal putu mahendra
 
Makalah Manajemen Keuangan
Makalah Manajemen KeuanganMakalah Manajemen Keuangan
Makalah Manajemen Keuangan
 
Proposal aq baru
Proposal aq baruProposal aq baru
Proposal aq baru
 
Cheat GTA PS 2
Cheat GTA PS 2Cheat GTA PS 2
Cheat GTA PS 2
 
UML
UMLUML
UML
 
Presentation msdm1.1
Presentation msdm1.1Presentation msdm1.1
Presentation msdm1.1
 
Teknik reparasi pc dan monitor
Teknik reparasi pc dan monitorTeknik reparasi pc dan monitor
Teknik reparasi pc dan monitor
 
Panduan praktis belajar komputer
Panduan praktis belajar komputerPanduan praktis belajar komputer
Panduan praktis belajar komputer
 
Fungsi vga onboard dan vga card
Fungsi vga onboard dan vga cardFungsi vga onboard dan vga card
Fungsi vga onboard dan vga card
 
Etika profesi & budi pekerti
Etika profesi & budi pekertiEtika profesi & budi pekerti
Etika profesi & budi pekerti
 

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 )