00001 <?php
00002
00003
00004
00005
00012 function mysql_is_available() {
00013 return function_exists('mysql_connect');
00014 }
00015
00022 function drupal_test_mysql($url, &$success) {
00023 if (!mysql_is_available()) {
00024 drupal_set_message(st('PHP MySQL support not enabled.'), 'error');
00025 return FALSE;
00026 }
00027
00028 $url = parse_url($url);
00029
00030
00031 $url['user'] = urldecode($url['user']);
00032 $url['pass'] = isset($url['pass']) ? urldecode($url['pass']) : '';
00033 $url['host'] = urldecode($url['host']);
00034 $url['path'] = urldecode($url['path']);
00035
00036
00037 if (isset($url['port'])) {
00038 $url['host'] = $url['host'] . ':' . $url['port'];
00039 }
00040
00041
00042 $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
00043 if (!$connection) {
00044 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');
00045 return FALSE;
00046 }
00047
00048
00049 if (!mysql_select_db(substr($url['path'], 1))) {
00050 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');
00051 return FALSE;
00052 }
00053
00054 $success = array('CONNECT');
00055
00056
00057 $query = 'CREATE TABLE drupal_install_test (id int NULL)';
00058 $result = mysql_query($query);
00059 if ($error = mysql_error()) {
00060 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');
00061 return FALSE;
00062 }
00063 $err = FALSE;
00064 $success[] = 'SELECT';
00065 $success[] = 'CREATE';
00066
00067
00068 $query = 'INSERT INTO drupal_install_test (id) VALUES (1)';
00069 $result = mysql_query($query);
00070 if ($error = mysql_error()) {
00071 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');
00072 $err = TRUE;
00073 }
00074 else {
00075 $success[] = 'INSERT';
00076 }
00077
00078
00079 $query = 'UPDATE drupal_install_test SET id = 2';
00080 $result = mysql_query($query);
00081 if ($error = mysql_error()) {
00082 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');
00083 $err = TRUE;
00084 }
00085 else {
00086 $success[] = 'UPDATE';
00087 }
00088
00089
00090 $query = 'DELETE FROM drupal_install_test';
00091 $result = mysql_query($query);
00092 if ($error = mysql_error()) {
00093 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');
00094 $err = TRUE;
00095 }
00096 else {
00097 $success[] = 'DELETE';
00098 }
00099
00100
00101 $query = 'DROP TABLE drupal_install_test';
00102 $result = mysql_query($query);
00103 if ($error = mysql_error()) {
00104 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');
00105 $err = TRUE;
00106 }
00107 else {
00108 $success[] = 'DROP';
00109 }
00110
00111 if ($err) {
00112 return FALSE;
00113 }
00114
00115 mysql_close($connection);
00116 return TRUE;
00117 }