X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fsql-functions.php;h=4f57bf88ca1a5a919899947f4d3fcbaf78c1f11e;hb=df4166450ac4788f58931bd5d30c617432a63f9d;hp=069f459d93a35b471a06883d80301c91d8799433;hpb=596c8ab32594401ca84abfbfe35513ddfff31bec;p=mailer.git diff --git a/inc/sql-functions.php b/inc/sql-functions.php index 069f459d93..4f57bf88ca 100644 --- a/inc/sql-functions.php +++ b/inc/sql-functions.php @@ -218,5 +218,65 @@ function getInsertSqlFromArray ($array, $tableName) { return $SQL; } +// Initializes the SQL link by bringing it up if set +function initSqlLink () { + // Do this only if link is down + assert(!SQL_IS_LINK_UP()); + + // Is the configuration data set? + if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['dbase']))) { + // Remove cache + unset($GLOBALS['is_sql_link_up']); + + // Connect to DB + SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__); + + // Is the link valid? + if (SQL_IS_LINK_UP()) { + // Enable exit on error + enableExitOnError(); + + // Is it a valid resource? + if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === TRUE) { + // Set database name (required for ext-optimize and ifSqlTableExists()) + setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']); + + // Remove MySQL array from namespace + unset($GLOBALS['mysql']); + + // Load cache + loadIncludeOnce('inc/load_cache.php'); + } else { + // Wrong database? + reportBug(__FILE__, __LINE__, 'Wrong database selected.'); + } + } else { + // No link to database! + reportBug(__FILE__, __LINE__, 'Database link is not yet up.'); + } + } else { + // Maybe you forgot to enter your database login? + reportBug(__FILE__, __LINE__, 'Database login is missing.'); + } +} + +// Imports given SQL dump from given (relative) path +function importSqlDump ($path, $dumpName) { + // Construct FQFN + $FQFN = getPath() . $path . '/' . $dumpName . '.sql'; + + // Is the file readable? + if (!isFileReadable($FQFN)) { + // Not found, which is bad + reportBug(__FILE__, __LINE__, sprintf("SQL dump %s/%s.sql is not readable.", $path, $dumpName)); + } // END - if + + // Then read it + $fileContent = readSqlDump($FQFN); + + // Merge it with existing SQL statements + mergeSqls(explode(";\n", $fileContent), 'install'); +} + // [EOF] ?>