Skip to content

Commit 14e7ba5

Browse files
committed
Update to add missing function
1 parent c6d249a commit 14e7ba5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

database.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,18 @@ function syslog_sql_save($array_items, $table_name, $key_cols = 'id', $autoinc =
134134
return sql_save($array_items, $table_name, $key_cols, $autoinc, $syslog_cnn);
135135
}
136136

137+
/* syslog_db_table_exists - checks whether a table exists
138+
@param $table - the name of the table
139+
@param $log - whether to log error messages, defaults to true
140+
@returns - (bool) the output of the sql query as a single variable */
141+
function syslog_db_table_exists($table, $log = true) {
142+
global $syslog_cnn;
143+
144+
preg_match("/([`]{0,1}(?<database>[\w_]+)[`]{0,1}\.){0,1}[`]{0,1}(?<table>[\w_]+)[`]{0,1}/", $table, $matches);
145+
if ($matches !== false && array_key_exists('table', $matches)) {
146+
$sql = 'SHOW TABLES LIKE \'' . $matches['table'] . '\'';
147+
return (db_fetch_cell($sql, '', $log, $syslog_cnn) ? true : false);
148+
}
149+
return false;
150+
}
151+

0 commit comments

Comments
 (0)