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