Ejemplo n.º 1
0
//======================================================
// Auto Commit Tests
//======================================================
include "{$test_dir}/auto_commit.inc.php";
//***********************************************************************
// Prepared Insert Query with Transactions
//***********************************************************************
print_header('Prepared Insert Query with Transaction');
// No Data with IDs of 10 or 11
$strsql = 'select * from contacts where id IN (?, ?)';
$strsql0 = 'select * from contacts where id IN (10, 11)';
$param1 = 10;
$param2 = 11;
$data1->prepare($strsql, array(&$param1, &$param2));
$data1->execute();
print_array($data1->data_key_assoc('id'));
// Turn off auto commit
$data1->auto_commit(false);
// Insert two test Rows
$strsql2 = 'insert into contacts (id, first_name, last_name, city, state) values (?, ?, ?, ?, ?)';
$params = array(10, 'bob', 'bobson', 'toowalk', 'MN');
$data1->prepare($strsql2);
$data1->execute($params);
$params = array(11, 'john', 'smith', 'Racine', 'WI');
$data1->prepare($strsql2);
$data1->execute($params);
$data1->commit();
print_sub_header('Inserted two rows and committed. They should exist...');
$data1->prepare($strsql);
$data1->execute(array(&$param1, &$param2));
$data = $data1->data_key_assoc('id');
Ejemplo n.º 2
0
function qdb_list($db_config, $strsql, $return_format = '', $opts = false)
{
    // New Data Transaction
    $data1 = new data_trans($db_config);
    if (!empty($opts['debug'])) {
        $data1->data_debug(true);
    }
    // Execute Query
    $query_result = $data1->data_query($strsql);
    // Return Result Set
    $rf_arr = explode(':', $return_format);
    if (empty($rf_arr[0])) {
        unset($rf_arr[0]);
    }
    if (count($rf_arr) < 1) {
        return $data1->data_assoc_result();
    } else {
        if (count($rf_arr) == 1) {
            return $data1->data_key_assoc($rf_arr[0]);
        } else {
            if (count($rf_arr) > 1) {
                return $data1->data_key_val($rf_arr[0], $rf_arr[1]);
            }
        }
    }
}