Merge branch 'ru-logo' into 'master'
[ssproject1617.git] / testcms-final-anon / install / diagnose.php
1 <?php
2
3 /*
4 Database connection test
5 */
6
7 $fields = array('host', 'user', 'pass', 'db');
8 $post = array();
9
10 foreach($fields as $field) {
11 $post[$field] = isset($_POST[$field]) ? $_POST[$field] : false;
12 }
13
14 if(empty($post['db'])) {
15 $errors[] = 'Please specify a database name';
16 }
17
18 if(empty($post['host'])) {
19 $errors[] = 'Please specify a database host';
20 }
21
22 // test database
23 if(empty($errors)) {
24 try {
25 $dsn = 'mysql:dbname=' . $post['db'] . ';host=' . $post['host'];
26 new PDO($dsn, $post['user'], $post['pass']);
27 } catch(PDOException $e) {
28 $errors[] = $e->getMessage();
29 }
30 }
31
32 // output response
33 header('Content-Type: text/plain');
34
35 if(empty($errors)) {
36 //no errors we're all gooood
37 echo 'good';
38 } else {
39 echo implode(', ', $errors);
40 }