Login   Register  
PHP Classes
elePHPant
Icontem

File: example_5.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Bogdan Lupandin  >  MySQL Access Wrapper  >  example_5.php  >  Download  
File: example_5.php
Role: Example script
Content type: text/plain
Description: Example showing how to undo a previous action
Class: MySQL Access Wrapper
MySQL database access wrapper
Author: By
Last change: Brought the example up to date with the main class
Date: 2 years ago
Size: 1,859 bytes
 

Contents

Class file image Download
<p>The source of this example is...</p>
<pre><code>
require_once "db.php";
$db = new db();

// We do NOT want to cache results when using transactions
$db->set_opts(array('cache_results' => false));

// Building the query
$sql = array(
    'test1' => 'val_erw',
    'test3' => 'val_24'
);

$where = array(
    'test2' => '242'
);

// Generating the UPDATE statement
$update = $db->build_update('test', $sql, $where);

// Printing the query used
echo $update;

// Starting the transaction
$db->transaction('BEGIN');

// Carrying out the UPDATE statement
$result = $db->resource($update);

if($result === true)
{
    $db->transaction('COMMIT');
    echo "&lt;p>Table updated successfully!</p>";
}
else
{
    $db->transaction('ROLLBACK');
    echo "&lt;p>There was an error updating the database!</p>";
}

$result = $db->fetch_rowset('SELECT * FROM test ORDER BY test2 ASC');

print_r($result);</code>
<p style="font-size: 20px;">And the result:</p>
<?php
require_once "db.php";
$db = new db();

// We do NOT want to cache results when using transactions
$db->set_opts(array('cache_results' => false));

// Building the query
$sql = array(
    
'test1' => 'val_erw',
    
'test3' => 'val_24'
);

$where = array(
    
'test2' => '242'
);

// Generating the UPDATE statement
$update $db->build_update('test'$sql$where);

// Printing the query used
echo $update;

// Starting the transaction
$db->transaction('BEGIN');

// Carrying out the UPDATE statement
$result $db->resource($update);

if(
$result === true)
{
    
$db->transaction('COMMIT');
    echo 
"<p>Table updated successfully!</p>";
}
else
{
    
$db->transaction('ROLLBACK');
    echo 
"<p>There was an error updating the database!</p>";
}

$result $db->fetch_rowset('SELECT * FROM test ORDER BY test2 ASC');

print_r($result);
?></pre>