1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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;
}
|