2 // $Id: install.mysql.inc,v 1.4 2006/12/27 13:02:34 drumm Exp $
4 // MySQL specific install functions
7 * Check if MySQL is available.
12 function mysql_is_available() {
13 return function_exists('mysql_connect');
17 * Check if we can connect to MySQL.
22 function drupal_test_mysql($url, &$success) {
23 if (!mysql_is_available()) {
24 drupal_set_message(st('PHP MySQL support not enabled.'), 'error');
28 $url = parse_url($url);
30 // Decode url-encoded information in the db connection string.
31 $url['user'] = urldecode($url['user']);
32 $url['pass'] = urldecode($url['pass']);
33 $url['host'] = urldecode($url['host']);
34 $url['path'] = urldecode($url['path']);
36 // Allow for non-standard MySQL port.
37 if (isset($url['port'])) {
38 $url['host'] = $url['host'] .':'. $url['port'];
41 // Test connecting to the database.
42 $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
44 drupal_set_message(st('Failure 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');
48 // Test selecting the database.
49 if (!mysql_select_db(substr($url['path'], 1))) {
50 drupal_set_message(st('We were able to connect to the MySQL database server (which means your username and password are valid) but not able to select your database. 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');
54 $success = array('CONNECT');
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('We were unable 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');
64 $success[] = 'SELECT';
65 $success[] = 'CREATE';
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('We were unable 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');
75 $success[] = 'INSERT';
79 $query = 'UPDATE drupal_install_test SET id = 2';
80 $result = mysql_query($query);
81 if ($error = mysql_error()) {
82 drupal_set_message(st('We were unable 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');
86 $success[] = 'UPDATE';
90 $query = 'LOCK TABLES drupal_install_test WRITE';
91 $result = mysql_query($query);
92 if ($error = mysql_error()) {
93 drupal_set_message(st('We were unable to lock a test table on your MySQL database server. We tried locking a table with the command %query and MySQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
101 $query = 'UNLOCK TABLES';
102 $result = mysql_query($query);
103 if ($error = mysql_error()) {
104 drupal_set_message(st('We were unable to unlock a test table on your MySQL database server. We tried unlocking a table with the command %query and MySQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error');
108 $success[] = 'UNLOCK';
112 $query = 'DELETE FROM drupal_install_test';
113 $result = mysql_query($query);
114 if ($error = mysql_error()) {
115 drupal_set_message(st('We were unable 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');
119 $success[] = 'DELETE';
123 $query = 'DROP TABLE drupal_install_test';
124 $result = mysql_query($query);
125 if ($error = mysql_error()) {
126 drupal_set_message(st('We were unable 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');
137 mysql_close($connection);