Here is a code snippet along with the functions (which are actually in other files, but presented here for reference). See last two lines which are the basis of my question.
Code: Select all
function tep_db_insert_id() {
return mysql_insert_id();
}
function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
reset($data);
if ($action == 'insert') {
$query = 'insert into ' . $table . ' (';
while (list($columns, ) = each($data)) {
$query .= $columns . ', ';
}
$query = substr($query, 0, -2) . ') values (';
reset($data);
while (list(, $value) = each($data)) {
switch ((string)$value) {
case 'now()':
$query .= 'now(), ';
break;
case 'null':
$query .= 'null, ';
break;
default:
$query .= '\'' . tep_db_input($value) . '\', ';
break;
}
}
$query = substr($query, 0, -2) . ')';
} elseif ($action == 'update') {
$query = 'update ' . $table . ' set ';
while (list($columns, $value) = each($data)) {
switch ((string)$value) {
case 'now()':
$query .= $columns . ' = now(), ';
break;
case 'null':
$query .= $columns .= ' = null, ';
break;
default:
$query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
break;
}
}
$query = substr($query, 0, -2) . ' where ' . $parameters;
}
return tep_db_query($query, $link);
}
function tep_db_query($query, $link = 'db_link') {
global $$link;
if (STORE_DB_TRANSACTIONS == 'true') {
error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
if (STORE_DB_TRANSACTIONS == 'true') {
$result_error = mysql_error();
error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
}
return $result;
}
tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
$order_products_id = tep_db_insert_id();
[ /syntax]
$order_products_id keeps resulting in zero, but everything in the previous line's execution provides correct results. Shouldn't the call to tep_db_insert_id() provide me the selection of the database I need the value from, or do I need to actually designate which database. If so, how? The value it should be returning is an auto-increment field (which I believe is a requirement for the mysql_insert_id() function).
Thanks!