Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Sérgio Moura Fé  >  MySQL Transact  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Use example of class.mysqltransaction.php
Class: MySQL Transact
Execute multiple MySQL queries in a transaction
Author: By
Last change:
Date: 2005-07-24 07:39
Size: 1,062 bytes
 

Contents

Class file image Download
<?php
// Instance a class. (access a class code to configure parameters).
require "class.mysqltransact.php";

// Define a database name
$dbname "Example";

// Create a database
mysql_create_db($dbname) or die("Database not created.");

// Select a database
mysql_select_db("$dbname");

// Start transaction
$trans = new MySQL_Transact($id);

// Execute updates
$trans->AddSql("CREATE TABLE Accounts (AccountNumber VARCHAR(5) NOT NULL, AccountName VARCHAR(50) NOT NULL, AccountSold DOUBLE NULL, PRIMARY KEY(AccountNumber)) TYPE = InnoDB;");
$trans->AddSQL("INSERT INTO Accounts (AccountNumber, AccountName) VALUES ('00001', 'Sergio Fe'), ('00002', 'Nadja Marinho')");
$trans->AddSQL("UPDATE Accounts SET AccountSold = 1200 WHERE AccountNumber='00001'");
$trans->AddSQL("UPDATE Accounts SET AccountSold = 1600 WHERE AccountNumber='00002'");

// Commit or rollback transaction
if ($trans->Execute())
    echo 
"Transaction success.";
else
    echo 
"Transaction aborted.";
    

?>
<hr size="1" color="#ff9900">
End. <?= date("d/M/y h:m:s"?>