diff options
author | Dries Buytaert <dries@buytaert.net> | 2006-07-13 13:14:25 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2006-07-13 13:14:25 +0000 |
commit | 1c75a210bdf85afeee33952fd50c1951999fecb4 (patch) | |
tree | 340e364ba1ea0e4f41c2cd7c80e66543caff8304 /includes/install.mysqli.inc | |
parent | e4e416d1f7037dbee8e06096a6c41368d011599c (diff) | |
download | brdo-1c75a210bdf85afeee33952fd50c1951999fecb4.tar.gz brdo-1c75a210bdf85afeee33952fd50c1951999fecb4.tar.bz2 |
- Patch #68926 by chx, jeremy, steven, eaton, webchick, amazon, neil, nedjo et al: an initial install system for Drupal core.
Diffstat (limited to 'includes/install.mysqli.inc')
-rw-r--r-- | includes/install.mysqli.inc | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/includes/install.mysqli.inc b/includes/install.mysqli.inc new file mode 100644 index 000000000..5363da136 --- /dev/null +++ b/includes/install.mysqli.inc @@ -0,0 +1,140 @@ +<?php + +// MySQLi specific install functions + +/** + * Check if MySQLi is available. + * + * @return + * TRUE/FALSE + */ +function mysqli_is_available() { + return function_exists('mysqli_connect'); +} + +/** + * Check if we can connect to MySQL. + * + * @return + * TRUE/FALSE + */ +function drupal_test_mysqli($url, &$success) { + if (!mysqli_is_available()) { + drupal_set_message('PHP MySQLi support not enabled.', 'error'); + return FALSE; + } + + $url = parse_url($url); + + // Decode url-encoded information in the db connection string. + $url['user'] = urldecode($url['user']); + $url['pass'] = urldecode($url['pass']); + $url['host'] = urldecode($url['host']); + $url['path'] = urldecode($url['path']); + + // Allow for non-standard MySQL port. + if (isset($url['port'])) { + $url['host'] = $url['host'] .':'. $url['port']; + } + + $connection = mysqli_init(); + @mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS); + if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) { + 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' => mysqli_errno())), 'error'); + return FALSE; + } + + // Test selecting the database. + if (mysqli_connect_errno() > 0) { + 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' => mysqli_error())), 'error'); + return FALSE; + } + + $success = array('CONNECT'); + + // Test CREATE. + $query = 'CREATE TABLE drupal_install_test (id int(1) NULL)'; + $result = mysqli_query($query); + if ($error = mysqli_error()) { + 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'); + return FALSE; + } + $err = FALSE; + $success[] = 'SELECT'; + $success[] = 'CREATE'; + + // Test INSERT. + $query = 'INSERT INTO drupal_install_test (id) VALUES (1)'; + $result = mysqli_query($query); + if ($error = mysqli_error()) { + 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'); + $err = TRUE; + } + else { + $success[] = 'INSERT'; + } + + // Test UPDATE. + $query = 'UPDATE drupal_install_test SET id = 2'; + $result = mysqli_query($query); + if ($error = mysqli_error()) { + 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'); + $err = TRUE; + } + else { + $success[] = 'UPDATE'; + } + + // Test LOCK. + $query = 'LOCK TABLES drupal_install_test WRITE'; + $result = mysqli_query($query); + if ($error = mysqli_error()) { + 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'); + $err = TRUE; + } + else { + $success[] = 'LOCK'; + } + + // Test UNLOCK. + $query = 'UNLOCK TABLES'; + $result = mysqli_query($query); + if ($error = mysqli_error()) { + 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'); + $err = TRUE; + } + else { + $success[] = 'UNLOCK'; + } + + // Test DELETE. + $query = 'DELETE FROM drupal_install_test'; + $result = mysqli_query($query); + if ($error = mysqli_error()) { + 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'); + $err = TRUE; + } + else { + $success[] = 'DELETE'; + } + + // Test DROP. + $query = 'DROP TABLE drupal_install_test'; + $result = mysqli_query($query); + if ($error = mysqli_error()) { + 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'); + $err = TRUE; + } + else { + $success[] = 'DROP'; + } + + if ($err) { + return FALSE; + } + + mysqli_close($connection); + return TRUE; +} + +?> |