webmaster@1
|
1 <?php |
webmaster@1
|
2 // $Id: install.mysqli.inc,v 1.12 2008/01/23 09:59:29 goba Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 // MySQLi specific install functions |
webmaster@1
|
5 |
webmaster@1
|
6 /** |
webmaster@1
|
7 * Check if MySQLi is available. |
webmaster@1
|
8 * |
webmaster@1
|
9 * @return |
webmaster@1
|
10 * TRUE/FALSE |
webmaster@1
|
11 */ |
webmaster@1
|
12 function mysqli_is_available() { |
webmaster@1
|
13 return function_exists('mysqli_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_mysqli($url, &$success) { |
webmaster@1
|
23 if (!mysqli_is_available()) { |
webmaster@1
|
24 drupal_set_message(st('PHP MySQLi 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 $connection = mysqli_init(); |
webmaster@1
|
37 @mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS); |
webmaster@1
|
38 if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) { |
webmaster@1
|
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'); |
webmaster@1
|
40 return FALSE; |
webmaster@1
|
41 } |
webmaster@1
|
42 |
webmaster@1
|
43 // Test selecting the database. |
webmaster@1
|
44 if (mysqli_connect_errno() > 0) { |
webmaster@1
|
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'); |
webmaster@1
|
46 return FALSE; |
webmaster@1
|
47 } |
webmaster@1
|
48 |
webmaster@1
|
49 $success = array('CONNECT'); |
webmaster@1
|
50 |
webmaster@1
|
51 // Test CREATE. |
webmaster@1
|
52 $query = 'CREATE TABLE drupal_install_test (id int NULL)'; |
webmaster@1
|
53 $result = mysqli_query($connection, $query); |
webmaster@1
|
54 if ($error = mysqli_error($connection)) { |
webmaster@1
|
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'); |
webmaster@1
|
56 return FALSE; |
webmaster@1
|
57 } |
webmaster@1
|
58 $err = FALSE; |
webmaster@1
|
59 $success[] = 'SELECT'; |
webmaster@1
|
60 $success[] = 'CREATE'; |
webmaster@1
|
61 |
webmaster@1
|
62 // Test INSERT. |
webmaster@1
|
63 $query = 'INSERT INTO drupal_install_test (id) VALUES (1)'; |
webmaster@1
|
64 $result = mysqli_query($connection, $query); |
webmaster@1
|
65 if ($error = mysqli_error($connection)) { |
webmaster@1
|
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'); |
webmaster@1
|
67 $err = TRUE; |
webmaster@1
|
68 } |
webmaster@1
|
69 else { |
webmaster@1
|
70 $success[] = 'INSERT'; |
webmaster@1
|
71 } |
webmaster@1
|
72 |
webmaster@1
|
73 // Test UPDATE. |
webmaster@1
|
74 $query = 'UPDATE drupal_install_test SET id = 2'; |
webmaster@1
|
75 $result = mysqli_query($connection, $query); |
webmaster@1
|
76 if ($error = mysqli_error($connection)) { |
webmaster@1
|
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'); |
webmaster@1
|
78 $err = TRUE; |
webmaster@1
|
79 } |
webmaster@1
|
80 else { |
webmaster@1
|
81 $success[] = 'UPDATE'; |
webmaster@1
|
82 } |
webmaster@1
|
83 |
webmaster@1
|
84 // Test DELETE. |
webmaster@1
|
85 $query = 'DELETE FROM drupal_install_test'; |
webmaster@1
|
86 $result = mysqli_query($connection, $query); |
webmaster@1
|
87 if ($error = mysqli_error($connection)) { |
webmaster@1
|
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'); |
webmaster@1
|
89 $err = TRUE; |
webmaster@1
|
90 } |
webmaster@1
|
91 else { |
webmaster@1
|
92 $success[] = 'DELETE'; |
webmaster@1
|
93 } |
webmaster@1
|
94 |
webmaster@1
|
95 // Test DROP. |
webmaster@1
|
96 $query = 'DROP TABLE drupal_install_test'; |
webmaster@1
|
97 $result = mysqli_query($connection, $query); |
webmaster@1
|
98 if ($error = mysqli_error($connection)) { |
webmaster@1
|
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'); |
webmaster@1
|
100 $err = TRUE; |
webmaster@1
|
101 } |
webmaster@1
|
102 else { |
webmaster@1
|
103 $success[] = 'DROP'; |
webmaster@1
|
104 } |
webmaster@1
|
105 |
webmaster@1
|
106 if ($err) { |
webmaster@1
|
107 return FALSE; |
webmaster@1
|
108 } |
webmaster@1
|
109 |
webmaster@1
|
110 mysqli_close($connection); |
webmaster@1
|
111 return TRUE; |
webmaster@1
|
112 } |