comparison includes/install.mysql.inc @ 1:c1f4ac30525a 6.0

Drupal 6.0
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:28:28 +0100
parents
children
comparison
equal deleted inserted replaced
0:5a113a1c4740 1:c1f4ac30525a
1 <?php
2 // $Id: install.mysql.inc,v 1.9 2008/01/23 09:59:29 goba Exp $
3
4 // MySQL specific install functions
5
6 /**
7 * Check if MySQL is available.
8 *
9 * @return
10 * TRUE/FALSE
11 */
12 function mysql_is_available() {
13 return function_exists('mysql_connect');
14 }
15
16 /**
17 * Check if we can connect to MySQL.
18 *
19 * @return
20 * TRUE/FALSE
21 */
22 function drupal_test_mysql($url, &$success) {
23 if (!mysql_is_available()) {
24 drupal_set_message(st('PHP MySQL support not enabled.'), 'error');
25 return FALSE;
26 }
27
28 $url = parse_url($url);
29
30 // Decode url-encoded information in the db connection string.
31 $url['user'] = urldecode($url['user']);
32 $url['pass'] = isset($url['pass']) ? urldecode($url['pass']) : '';
33 $url['host'] = urldecode($url['host']);
34 $url['path'] = urldecode($url['path']);
35
36 // Allow for non-standard MySQL port.
37 if (isset($url['port'])) {
38 $url['host'] = $url['host'] .':'. $url['port'];
39 }
40
41 // Test connecting to the database.
42 $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
43 if (!$connection) {
44 drupal_set_message(st('Failed to connect to your MySQL database server. MySQL reports the following message: %error.<ul><li>Are you sure you have the correct username and password?</li><li>Are you sure that you have typed the correct database hostname?</li><li>Are you sure that the database server is running?</li></ul>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%error' => mysql_error())), 'error');
45 return FALSE;
46 }
47
48 // Test selecting the database.
49 if (!mysql_select_db(substr($url['path'], 1))) {
50 drupal_set_message(st('Failed to select your database on your MySQL database server, which means the connection username and password are valid, but there is a problem accessing your data. MySQL reports the following message: %error.<ul><li>Are you sure you have the correct database name?</li><li>Are you sure the database exists?</li><li>Are you sure the username has permission to access the database?</li></ul>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%error' => mysql_error())), 'error');
51 return FALSE;
52 }
53
54 $success = array('CONNECT');
55
56 // Test CREATE.
57 $query = 'CREATE TABLE drupal_install_test (id int NULL)';
58 $result = mysql_query($query);
59 if ($error = mysql_error()) {
60 drupal_set_message(st('Failed to create a test table on your MySQL database server with the command %query. MySQL reports the following message: %error.<ul><li>Are you sure the configured username has the necessary MySQL permissions to create tables in the database?</li></ul>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%query' => $query, '%error' => $error)), 'error');
61 return FALSE;
62 }
63 $err = FALSE;
64 $success[] = 'SELECT';
65 $success[] = 'CREATE';
66
67 // Test INSERT.
68 $query = 'INSERT INTO drupal_install_test (id) VALUES (1)';
69 $result = mysql_query($query);
70 if ($error = mysql_error()) {
71 drupal_set_message(st('Failed to insert a value into a test table on your MySQL database server. We tried inserting a value with the command %query and MySQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
72 $err = TRUE;
73 }
74 else {
75 $success[] = 'INSERT';
76 }
77
78 // Test UPDATE.
79 $query = 'UPDATE drupal_install_test SET id = 2';
80 $result = mysql_query($query);
81 if ($error = mysql_error()) {
82 drupal_set_message(st('Failed to update a value in a test table on your MySQL database server. We tried updating a value with the command %query and MySQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
83 $err = TRUE;
84 }
85 else {
86 $success[] = 'UPDATE';
87 }
88
89 // Test DELETE.
90 $query = 'DELETE FROM drupal_install_test';
91 $result = mysql_query($query);
92 if ($error = mysql_error()) {
93 drupal_set_message(st('Failed to delete a value from a test table on your MySQL database server. We tried deleting a value with the command %query and MySQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
94 $err = TRUE;
95 }
96 else {
97 $success[] = 'DELETE';
98 }
99
100 // Test DROP.
101 $query = 'DROP TABLE drupal_install_test';
102 $result = mysql_query($query);
103 if ($error = mysql_error()) {
104 drupal_set_message(st('Failed to drop a test table from your MySQL database server. We tried dropping a table with the command %query and MySQL reported the following error %error.', array('%query' => $query, '%error' => $error)), 'error');
105 $err = TRUE;
106 }
107 else {
108 $success[] = 'DROP';
109 }
110
111 if ($err) {
112 return FALSE;
113 }
114
115 mysql_close($connection);
116 return TRUE;
117 }