// Escape a string for the database
function SQL_ESCAPE($str) {
global $link;
+
if (!is_resource($link)) {
// Fall-back to addslashes() when there is no link
return addslashes($str);
- }
+ } // END - if
if (function_exists('mysql_real_escape_string')) {
// The new and improved version
// Return the result
return SQL_QUERY_ESC($SQL, array(bigintval($id)), __FILE__, __LINE__);
}
+// ALTER TABLE wrapper function
+function SQL_ALTER_TABLE($sql, $F, $L) {
+ // Shall we add?
+ if (eregi("ADD", $sql) > 0) {
+ // Extract table name
+ $tableArray = explode(" ", $sql);
+ $tableName = str_replace("`", "", $tableArray[2]);
+
+ // And column name as well
+ $columnName = str_replace("`", "", $tableArray[4]);
+
+ // Get column information
+ $result = SQL_QUERY_ESC("SHOW COLUMNS FROM %s LIKE '%s'",
+ array($tableName, $columnName), __FILE__, __LINE__);
+
+ // Do we have no entry?
+ if (SQL_NUMROWS($result) == 0) {
+ // Do the query
+ return SQL_QUERY($sql, $F, $L, false);
+ } // END - if
+ } else {
+ // Send it to the SQL_QUERY() function
+ return SQL_QUERY($sql, $F, $L, false);
+ }
+}
//
?>