forked from tsugiproject/tsugi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanity-db.php
105 lines (100 loc) · 4.61 KB
/
sanity-db.php
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
// Lets check to see if we have a database or not and give a decent error message
try {
if ( ! defined('PDO_WILL_CATCH') ) define('PDO_WILL_CATCH', true);
require_once("pdo.php");
} catch(PDOException $ex){
$msg = $ex->getMessage();
error_log("DB connection: ".$msg);
echo('<div class="alert alert-danger" style="margin: 10px;">'."\n");
if ( strpos($msg, 'Unknown database') !== false ) {
echo("<p>It does not appear as though your database exists.</p>
<p> If you have full access to your MySql instance (i.e. like
MAMP or XAMPP, you may need to run commands like this:</p>
<pre>
CREATE DATABASE tsugi DEFAULT CHARACTER SET utf8;
GRANT ALL ON tsugi.* TO 'ltiuser'@'localhost' IDENTIFIED BY 'ltipassword';
GRANT ALL ON tsugi.* TO 'ltiuser'@'127.0.0.1' IDENTIFIED BY 'ltipassword';
</pre>
<p>Make sure to choose appropriate passwords when setting this up.</p>
<p>If you are running in a hosted environment and are using an admin tool like
CPanel (or equivalent). You must user this interface to create a database,
user, and password.</p>
<p>
In some systems, a database adminstrator will create the database,
user, and password and simply give them to you.
<p>
Once you have the database, account and password you must update your
<code>config.php</code> with this information.</p>
");
} else if ( strpos($msg, 'Access denied for user') !== false ) {
echo('<p>It appears that you are unable to access
your database due to a problem with the user and password.
The user and password for the database conneciton are setup using either a
SQL <code>GRANT</code> command or created in an adminstration tool like CPanel.
Or perhaps a system administrator created the database and gave you the
account and password to access the database.</p>
<p>Make sure to check the values in your <code>config.php</code> for
<pre>
$CFG->dbuser = \'ltiuser\';
$CFG->dbpass = \'ltipassword\';
</pre>
To make sure they match the account and password assigned to your database.
</p>
');
} else if ( strpos($msg, 'Can\'t connect to MySQL server') !== false ) {
echo('<p>It appears that you cannot connect to your MySQL server at
all. The most likely problem is the wrong host or port in this option
in your <code>config.php</code> file:
<pre>
$CFG->pdo = \'mysql:host=127.0.0.1;dbname=tsugi\';
# $CFG->pdo = \'mysql:host=127.0.0.1;port=8889;dbname=tsugi\'; // MAMP
</pre>
The host may be incorrect - you might try switching from \'127.0.0.1\' to
\'localhost\'. Or if you are on a hosted system with an ISP the name of the
database host might be given to you like \'db4263.mysql.1and1.com\' and you
need to put that host name in the PDO string.</p>
<p>
Most systems are configured to use the default MySQL port of 3306 and if you
omit "port=" in the PDO string it assumes 3306. If you are using MAMP
this is usually moved to port 8889. If neither 3306 nor 8889 works you
probably have a bad host name. Or talk to your system administrator.
</p>
');
} else {
echo("<p>There is a problem with your database connection.</p>\n");
}
echo("<p>Database error detail: ".$msg."</p>\n");
echo("<p>Once you have fixed the problem, come back to this page and refresh
to see if this message goes away.</p>");
echo('<p>Installation instructions are avaiable at <a href="http://www.tsugi.org/"
target="_blank">tsugi.org</a>');
echo("\n</div>\n");
die_with_error_log("Database error ".$msg);
}
// Now check the plugins table to see if it exists
$p = $CFG->dbprefix;
$plugins = "{$p}lms_plugins";
$table_fields = $PDOX->metadata($plugins);
if ( $table_fields === false ) {
echo('<div class="alert alert-danger" style="margin: 10px;">'."\n");
echo("<p>It appears that your database connection is working properly
but you have no tables in your database. To create the initial tables
needed for this application, use the 'Admin' feature. You will be prompted
for the administrator master password as configured in <code>config.php</code>
in the <code>\$CFG->adminpw</code> setting.
</p>
");
echo("\n</div>\n");
// Now check to see if a database upgrade might be necessary
} else {
$row = $PDOX->rowDie("SELECT MAX(version) AS version FROM {$plugins}");
$actualdbversion = $row['version'];
if ( $actualdbversion < $CFG->dbversion ) {
echo('<div class="alert alert-danger" style="margin: 10px;">'."\n");
echo("<p>Warning: Database version=$actualdbversion should be
software version=$CFG->dbversion - please run admin/upgrade.php</p>\n");
echo("\n</div>\n");
error_log("Warning: DB current version=$actualdbversion expected version=$CFG->dbversion");
}
}