public function delete($pkey_values = '', $pre_args = array(), $post_args = array()) { // Check for pre_delete() if (method_exists($this, 'pre_delete')) { if (!is_array($pre_args)) { $pre_args = array($pre_args); } call_user_func_array(array($this, 'pre_delete'), $pre_args); } if (!empty($pkey_values)) { $qa = array(); $qa['type'] = 'delete'; // Set Table if (isset($this->schema)) { $qa['table'] = "{$this->schema}.{$this->table}"; } else { $qa['table'] = $this->table; } $qa['filter_phrase'] = $this->build_where($pkey_values); $query = new data_query($qa); $strsql = $query->render(); if ($this->print_trans) { print $strsql; if ($this->use_bind_params) { ob_start(); print "<br/><pre>\n"; print_r($this->bind_params); print "</pre>\n"; $ret_val .= ob_get_clean(); } } else { // Create a new data transaction and execute query $data1 = new data_trans($this->data_source); // Use Bind Parameters if ($this->use_bind_params) { // Prepare Query $prep_status = $data1->prepare($strsql); // Execute Query $exec_status = $data1->execute($this->bind_params); // Reset Bind Variables $this->reset_bind_vars(); } else { $query_result = $data1->data_query($strsql); } } } else { trigger_error("Error: [{$this->class_name}]::delete(): No primary key(s) given.", E_USER_ERROR); } // Check for post_delete() if (method_exists($this, 'post_delete')) { if (!is_array($post_args)) { $post_args = array($post_args); } call_user_func_array(array($this, 'post_delete'), $post_args); } }
//====================================================== include "{$test_dir}/dio_test.inc.php"; //====================================================== // 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);
function qdb_lookup($data_source, $sql, $fields = '', $bind_params = false, $opts = false) { // Check if fields are not specified if ($fields == '') { trigger_error('ERROR: qdb_lookup(): No return fields specified!!'); } // New Data Transaction $data1 = new data_trans($data_source); if (!empty($opts['debug'])) { $data1->data_debug(true); } $data1->set_opt('make_bind_params_refs', 1); // Use Bind Parameters if (is_array($bind_params) && count($bind_params)) { // Prepare Query $prep_status = $data1->prepare($sql); // Execute Query $exec_status = $data1->execute($bind_params); } else { // Execute Query $query_result = $data1->data_query($sql); } // Pull result set $result = $data1->data_assoc_result(); // If result set empty, return false if (count($result) <= 0) { return false; } else { // Multiple fields specified if (is_array($fields)) { $return_vals = array(); foreach ($fields as $index) { if (array_key_exists($index, $result[0])) { $return_vals[$index] = $result[0][$index]; } else { trigger_error("ERROR: qdb_lookup(): Field '{$index}' does not exist in record set!!"); } } } else { if (array_key_exists($fields, $result[0])) { return $result[0][$fields]; } else { trigger_error("ERROR: qdb_lookup(): Field '{$fields}' does not exist in record set!!"); } } } }