[b354002] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // MySQL specific install functions |
---|
| 4 | |
---|
| 5 | /** |
---|
| 6 | * Check if MySQL is available. |
---|
| 7 | * |
---|
| 8 | * @return |
---|
| 9 | * TRUE/FALSE |
---|
| 10 | */ |
---|
| 11 | function mysql_is_available() { |
---|
| 12 | return function_exists('mysql_connect'); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | /** |
---|
| 16 | * Check if we can connect to MySQL. |
---|
| 17 | * |
---|
| 18 | * @return |
---|
| 19 | * TRUE/FALSE |
---|
| 20 | */ |
---|
| 21 | function drupal_test_mysql($url, &$success) { |
---|
| 22 | if (!mysql_is_available()) { |
---|
| 23 | drupal_set_message(st('PHP MySQL support not enabled.'), 'error'); |
---|
| 24 | return FALSE; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | $url = parse_url($url); |
---|
| 28 | |
---|
| 29 | // Decode url-encoded information in the db connection string. |
---|
| 30 | $url['user'] = urldecode($url['user']); |
---|
| 31 | $url['pass'] = isset($url['pass']) ? urldecode($url['pass']) : ''; |
---|
| 32 | $url['host'] = urldecode($url['host']); |
---|
| 33 | $url['path'] = urldecode($url['path']); |
---|
| 34 | |
---|
| 35 | // Allow for non-standard MySQL port. |
---|
| 36 | if (isset($url['port'])) { |
---|
| 37 | $url['host'] = $url['host'] .':'. $url['port']; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | // Test connecting to the database. |
---|
| 41 | $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2); |
---|
| 42 | if (!$connection) { |
---|
| 43 | 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'); |
---|
| 44 | return FALSE; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | // Test selecting the database. |
---|
| 48 | if (!mysql_select_db(substr($url['path'], 1))) { |
---|
| 49 | 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'); |
---|
| 50 | return FALSE; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | $success = array('CONNECT'); |
---|
| 54 | |
---|
| 55 | // Test CREATE. |
---|
| 56 | $query = 'CREATE TABLE drupal_install_test (id int NULL)'; |
---|
| 57 | $result = mysql_query($query); |
---|
| 58 | if ($error = mysql_error()) { |
---|
| 59 | 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'); |
---|
| 60 | return FALSE; |
---|
| 61 | } |
---|
| 62 | $err = FALSE; |
---|
| 63 | $success[] = 'SELECT'; |
---|
| 64 | $success[] = 'CREATE'; |
---|
| 65 | |
---|
| 66 | // Test INSERT. |
---|
| 67 | $query = 'INSERT INTO drupal_install_test (id) VALUES (1)'; |
---|
| 68 | $result = mysql_query($query); |
---|
| 69 | if ($error = mysql_error()) { |
---|
| 70 | 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'); |
---|
| 71 | $err = TRUE; |
---|
| 72 | } |
---|
| 73 | else { |
---|
| 74 | $success[] = 'INSERT'; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | // Test UPDATE. |
---|
| 78 | $query = 'UPDATE drupal_install_test SET id = 2'; |
---|
| 79 | $result = mysql_query($query); |
---|
| 80 | if ($error = mysql_error()) { |
---|
| 81 | 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'); |
---|
| 82 | $err = TRUE; |
---|
| 83 | } |
---|
| 84 | else { |
---|
| 85 | $success[] = 'UPDATE'; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | // Test DELETE. |
---|
| 89 | $query = 'DELETE FROM drupal_install_test'; |
---|
| 90 | $result = mysql_query($query); |
---|
| 91 | if ($error = mysql_error()) { |
---|
| 92 | 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'); |
---|
| 93 | $err = TRUE; |
---|
| 94 | } |
---|
| 95 | else { |
---|
| 96 | $success[] = 'DELETE'; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | // Test DROP. |
---|
| 100 | $query = 'DROP TABLE drupal_install_test'; |
---|
| 101 | $result = mysql_query($query); |
---|
| 102 | if ($error = mysql_error()) { |
---|
| 103 | 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'); |
---|
| 104 | $err = TRUE; |
---|
| 105 | } |
---|
| 106 | else { |
---|
| 107 | $success[] = 'DROP'; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | if ($err) { |
---|
| 111 | return FALSE; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | mysql_close($connection); |
---|
| 115 | return TRUE; |
---|
| 116 | } |
---|