summaryrefslogtreecommitdiff
path: root/installer/include.php
diff options
context:
space:
mode:
Diffstat (limited to 'installer/include.php')
-rw-r--r--installer/include.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/installer/include.php b/installer/include.php
new file mode 100644
index 0000000..7300e90
--- /dev/null
+++ b/installer/include.php
@@ -0,0 +1,81 @@
+<?php
+
+function mm_getParam($name, $default='') {
+ if (isset($_POST[$name])) {
+ return $_POST[$name];
+ } else {
+ return $default;
+ }
+}
+
+function mm_configStr($param) {
+ return "\$db_config['$param'] = \"".$_POST["db_$param"]."\";\n";
+}
+
+function mm_isSqlConfigured($conf_file) {
+ if (file_exists($conf_file)) {
+ global $db_config;
+ require($conf_file);
+ if (isset($db_config)) {
+ unset($db_config);
+ return true;
+ }
+ }
+ return false;
+}
+
+function mm_mysql_create_db($mysql, $db_name, &$r) {
+ global $t;
+ if ($mysql) {
+ $db_list = mysql_list_dbs($mysql);
+ $db_array = Array();
+ while ($row = mysql_fetch_object($db_list)) {
+ $db_array[] = $row->Database . '';
+ }
+ $r.=$t->inputP("Existing databases: ".implode(', ',$db_array));
+
+ if (!in_array($db_name, $db_array)) {
+ $str.=$t->inputP("Creating database <q>$db_name</q>...");
+ $db = mysql_query("CREATE DATABASE $db_name;", $mysql);
+ if ($db===FALSE) {
+ $str.=$t->inputP("Database <q>$db_name</q> ".
+ "could not be created: ".
+ mysql_error($mysql), true);
+ return false;
+ }
+ }
+ $r.=$t->inputP("Selecting database <q>$db_name</q>...");
+ $db = mysql_select_db($db_name, $mysql);
+ if (!$db) {
+ $r.=$t->inputP('Could not select database: ',
+ mysql_error($mysql), true);
+ return false;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function mm_mysql_count_rows_in_table($mysql, $table_name) {
+ $table=mysql_real_escape_string($table_name);
+ $query =
+ "SELECT COUNT(*)\n".
+ "FROM $table;";
+ $total = mysql_query($query, $mysql);
+ $total = mysql_fetch_array($total);
+ $total = $total[0];
+ return $total;
+}
+
+function mm_mysql_table_exists($mysql, $table_name) {
+ $table=mysql_real_escape_string($table_name);
+ $query =
+ "SELECT COUNT(*)\n".
+ "FROM information_schema.tables\n".
+ "WHERE table_name = '$table';";
+ $total = mysql_query($query, $mysql);
+ $total = mysql_fetch_array($total);
+ $total = $total[0];
+ return $total>0;
+}