Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions Sources/Subs-Db-mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,26 +840,30 @@ function smf_db_insert($method, $table, $columns, $data, $keys, $returnmode = 0,
// the inserted value already exists we need to find the pk
else
{
$where_string = '';
$count2 = count($keys);
for ($x = 0; $x < $count2; $x++)
$where_string = [];

foreach ($columns as $column_name => $type)
{
$keyPos = array_search($keys[$x], array_keys($columns));
$where_string .= $keys[$x] . ' = ' . $data[$i][$keyPos];
if (($x + 1) < $count2)
$where_string .= ' AND ';
if (str_contains($type, 'string-'))
$where_string[] = $column_name . ' = ' . sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . ')', $column_name);
else
$where_string[] = $column_name . ' = ' . sprintf('{%1$s:%2$s}', $type, $column_name);
}

$where_string = implode(' AND ', $where_string);

$request = $smcFunc['db_query']('', '
SELECT `' . $keys[0] . '` FROM ' . $table . '
WHERE ' . $where_string . ' LIMIT 1',
array()
SELECT ' . $keys[0] . '
FROM ' . $table . '
WHERE ' . $where_string . '
LIMIT 1',
array_combine($indexed_columns, $data[$i])
);

if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
{
$row = $smcFunc['db_fetch_assoc']($request);
$ai = $row[$keys[0]];
$ai = (int) $row[$keys[0]];
}
}

Expand Down
Loading