関数・クラス解説

sqlsrv_commit

version:No version information available (公式)

Commits a transaction that was begun with sqlsrv_begin_transaction()

公式リファレンス

書式

sqlsrv_commit ( resource $conn ) : bool

説明

Commits a transaction that was begun with sqlsrv_begin_transaction(). The connection is returned to auto-commit mode after sqlsrv_commit() is called. The transaction that is committed includes all statements that were executed after the call to sqlsrv_begin_transaction(). Explicit transactions should be started and committed or rolled back using these functions instead of executing SQL statements that begin and commit/roll back transactions. For more information, see » SQLSRV Transactions.

パラメータ

conn
The connection on which the transaction is to be committed.

返値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

サンプル

例1 sqlsrv_commit() example

The following example demonstrates how to use sqlsrv_commit() together with sqlsrv_begin_transaction() and sqlsrv_rollback().

$serverName = "serverName\sqlexpress"; $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."; } else {      sqlsrv_rollback( $conn );      echo "Transaction rolled back."; }

参考

  • sqlsrv_begin_transaction() - Begins a database transaction
  • sqlsrv_rollback() - Rolls back a transaction that was begun with sqlsrv_begin_transaction
  • ワード検索


    ※入力キーワードが、関数名・説明文・タグに含まれるものを検索

    関数名アルファベット別

    A B C D E F G H I J
    K L M N O P Q R S T
    U V W X Y Z _

    最終更新一覧

    stristr
     大文字小文字を区別せず文字列を検索し、ヒット箇所以降(あるいは以前)の文字列を返却

    stripslashes
     バックスラッシュでエスケープされた文字列から、バックスラッシュを取り除く

    stripos
     大文字小文字を区別せずに文字列が最初に現れる位置を取得する

    stripcslashes
     addcslashes() でクォートされた文字列をアンクォートする

    strip_tags
     文字列から HTML と PHP のタグを除去して返却

    strcspn
     指定した文字が最初に現れる位置を調べる

    strcoll
     ロケールに基づいて2つの文字列を比較し同じか(あるいは大小)を判定する

    strcmp
     2つの文字列を比較し同じか(あるいは大小)を判定する

    strchr
     strstr() のエイリアス

    strcasecmp
     2つの文字列を比較(大文字小文字を区別せず同じとみなす)

    カテゴリー一覧

    PHP の振る舞いの変更
    音声フォーマットの操作
    認証サービス
    コマンドライン関連
    圧縮およびアーカイブ
    暗号
    データベース関連
    日付および時刻関連
    ファイルシステム
    自然言語および文字エンコーディング
    画像処理および作成
    メール関連
    数学
    テキスト以外の MIME 型
    プロセス制御
    その他の基本モジュール
    その他のサービス
    検索エンジン用の拡張モジュール
    サーバー固有のモジュール
    セッション関連
    テキスト処理
    変数・データ型関連
    ウェブサービス
    Windows 用のモジュール
    XML 操作
    GUI用の拡張モジュール