Mercurial > defr > drupal > core
comparison includes/install.mysqli.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 |
comparison
equal
deleted
inserted
replaced
| 0:5a113a1c4740 | 1:c1f4ac30525a |
|---|---|
| 1 <?php | |
| 2 // $Id: install.mysqli.inc,v 1.12 2008/01/23 09:59:29 goba Exp $ | |
| 3 | |
| 4 // MySQLi specific install functions | |
| 5 | |
| 6 /** | |
| 7 * Check if MySQLi is available. | |
| 8 * | |
| 9 * @return | |
| 10 * TRUE/FALSE | |
| 11 */ | |
| 12 function mysqli_is_available() { | |
| 13 return function_exists('mysqli_connect'); | |
| 14 } | |
| 15 | |
| 16 /** | |
| 17 * Check if we can connect to MySQL. | |
| 18 * | |
| 19 * @return | |
| 20 * TRUE/FALSE | |
| 21 */ | |
| 22 function drupal_test_mysqli($url, &$success) { | |
| 23 if (!mysqli_is_available()) { | |
| 24 drupal_set_message(st('PHP MySQLi support not enabled.'), 'error'); | |
| 25 return FALSE; | |
| 26 } | |
| 27 | |
| 28 $url = parse_url($url); | |
| 29 | |
| 30 // Decode url-encoded information in the db connection string. | |
| 31 $url['user'] = urldecode($url['user']); | |
| 32 $url['pass'] = isset($url['pass']) ? urldecode($url['pass']) : ''; | |
| 33 $url['host'] = urldecode($url['host']); | |
| 34 $url['path'] = urldecode($url['path']); | |
| 35 | |
| 36 $connection = mysqli_init(); | |
| 37 @mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS); | |
| 38 if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) { | |
| 39 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' => mysqli_connect_error())), 'error'); | |
| 40 return FALSE; | |
| 41 } | |
| 42 | |
| 43 // Test selecting the database. | |
| 44 if (mysqli_connect_errno() > 0) { | |
| 45 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' => mysqli_connect_error())), 'error'); | |
| 46 return FALSE; | |
| 47 } | |
| 48 | |
| 49 $success = array('CONNECT'); | |
| 50 | |
| 51 // Test CREATE. | |
| 52 $query = 'CREATE TABLE drupal_install_test (id int NULL)'; | |
| 53 $result = mysqli_query($connection, $query); | |
| 54 if ($error = mysqli_error($connection)) { | |
| 55 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'); | |
| 56 return FALSE; | |
| 57 } | |
| 58 $err = FALSE; | |
| 59 $success[] = 'SELECT'; | |
| 60 $success[] = 'CREATE'; | |
| 61 | |
| 62 // Test INSERT. | |
| 63 $query = 'INSERT INTO drupal_install_test (id) VALUES (1)'; | |
| 64 $result = mysqli_query($connection, $query); | |
| 65 if ($error = mysqli_error($connection)) { | |
| 66 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'); | |
| 67 $err = TRUE; | |
| 68 } | |
| 69 else { | |
| 70 $success[] = 'INSERT'; | |
| 71 } | |
| 72 | |
| 73 // Test UPDATE. | |
| 74 $query = 'UPDATE drupal_install_test SET id = 2'; | |
| 75 $result = mysqli_query($connection, $query); | |
| 76 if ($error = mysqli_error($connection)) { | |
| 77 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'); | |
| 78 $err = TRUE; | |
| 79 } | |
| 80 else { | |
| 81 $success[] = 'UPDATE'; | |
| 82 } | |
| 83 | |
| 84 // Test DELETE. | |
| 85 $query = 'DELETE FROM drupal_install_test'; | |
| 86 $result = mysqli_query($connection, $query); | |
| 87 if ($error = mysqli_error($connection)) { | |
| 88 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'); | |
| 89 $err = TRUE; | |
| 90 } | |
| 91 else { | |
| 92 $success[] = 'DELETE'; | |
| 93 } | |
| 94 | |
| 95 // Test DROP. | |
| 96 $query = 'DROP TABLE drupal_install_test'; | |
| 97 $result = mysqli_query($connection, $query); | |
| 98 if ($error = mysqli_error($connection)) { | |
| 99 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'); | |
| 100 $err = TRUE; | |
| 101 } | |
| 102 else { | |
| 103 $success[] = 'DROP'; | |
| 104 } | |
| 105 | |
| 106 if ($err) { | |
| 107 return FALSE; | |
| 108 } | |
| 109 | |
| 110 mysqli_close($connection); | |
| 111 return TRUE; | |
| 112 } |
