oci_pdo_transaction1.htm
Objectives:
  • Create a table
    CREATE TABLE mystaff( id NUMBER(2), fname VARCHAR2(20), lname VARCHAR2(30))
  • Add an unique constraints
    • ALTER TABLE mystaff
       ADD CONSTRAINT uq1 UNIQUE (id) DISABLE
  • Disable and enable the constraint
    • ALTER TABLE mystaff ENABLE CONSTRAINT uq1
  • Insert data using pdo-transaction  application (custom)
    try {
    $dbh = new PDO("oci:dbname=".$tns,$db_username,$db_password);
    echo "Connected\n";
    } catch (Exception $e) {
    die("Unable to connect: " . $e->getMessage());
    }
    try {
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbh->beginTransaction();
    //$dbh->exec("insert into staff (id, first, last) values (23, 'David', 'Mukherjee')");
    $dbh->exec($sql);
    $dbh->commit();
    } catch (Exception $e) {
    $dbh->rollBack();
    echo "Failed: " . $e->getMessage();
    }
     
Step:1 Creating a table,  mystaff

CREATE TABLE mystaff( id NUMBER(2), fname VARCHAR2(20), lname VARCHAR2(30))

Check this empty table

Step:2Adding Unique constraints

ALTER TABLE mystaff ADD CONSTRAINT uq1 UNIQUE (id) DISABLE

Verifying unique constraints

Step:3 Enable Unique constraint

ALTER TABLE mystaff ENABLE CONSTRAINT uq1

VERIFY :

SELECT TABLE_NAME, CONSTRAINT_NAME, STATUS FROM USER_CONSTRAINTS

Step:4: inserting data n this table using pdo_transaction application

insert into mystaff (id, fname, lname) values (10, 'Dan', 'Parker')

Verifying the above insert query

Step:5 Testing Rollover: id was 4 digit integer

insert into mystaff (id, fname, lname) values (1001, 'Peter', 'Pan')

Now add id that would be 2 digit integer

Verify the above action.