Mercurial > defr > drupal > core
comparison includes/install.pgsql.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.pgsql.inc,v 1.6 2007/10/22 15:22:39 dries Exp $ | |
| 3 | |
| 4 // PostgreSQL specific install functions | |
| 5 | |
| 6 /** | |
| 7 * Check if PostgreSQL is available. | |
| 8 * | |
| 9 * @return | |
| 10 * TRUE/FALSE | |
| 11 */ | |
| 12 function pgsql_is_available() { | |
| 13 return function_exists('pg_connect'); | |
| 14 } | |
| 15 | |
| 16 /** | |
| 17 * Check if we can connect to PostgreSQL. | |
| 18 * | |
| 19 * @return | |
| 20 * TRUE/FALSE | |
| 21 */ | |
| 22 function drupal_test_pgsql($url, &$success) { | |
| 23 if (!pgsql_is_available()) { | |
| 24 drupal_set_message(st('PHP PostgreSQL support not enabled.'), 'error'); | |
| 25 return FALSE; | |
| 26 } | |
| 27 | |
| 28 $url = parse_url($url); | |
| 29 $conn_string = ''; | |
| 30 | |
| 31 // Decode url-encoded information in the db connection string | |
| 32 if (isset($url['user'])) { | |
| 33 $conn_string .= ' user='. urldecode($url['user']); | |
| 34 } | |
| 35 if (isset($url['pass'])) { | |
| 36 $conn_string .= ' password='. urldecode($url['pass']); | |
| 37 } | |
| 38 if (isset($url['host'])) { | |
| 39 $conn_string .= ' host='. urldecode($url['host']); | |
| 40 } | |
| 41 if (isset($url['path'])) { | |
| 42 $conn_string .= ' dbname='. substr(urldecode($url['path']), 1); | |
| 43 } | |
| 44 if (isset($url['port'])) { | |
| 45 $conn_string .= ' port='. urldecode($url['port']); | |
| 46 } | |
| 47 | |
| 48 // Test connecting to the database. | |
| 49 $connection = @pg_connect($conn_string); | |
| 50 if (!$connection) { | |
| 51 drupal_set_message(st('Failed to connect to your PostgreSQL database server. PostgreSQL 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><li>Are you sure you typed the correct database name?</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' => 'Connection failed. See log file for failure reason')), 'error'); | |
| 52 return FALSE; | |
| 53 } | |
| 54 | |
| 55 $success = array('CONNECT'); | |
| 56 | |
| 57 // Test CREATE. | |
| 58 $query = 'CREATE TABLE drupal_install_test (id integer NOT NULL)'; | |
| 59 $result = pg_query($connection, $query); | |
| 60 if ($error = pg_result_error($result)) { | |
| 61 drupal_set_message(st('Failed to create a test table on your PostgreSQL database server with the command %query. PostgreSQL reports the following message: %error.<ul><li>Are you sure the configured username has the necessary PostgreSQL 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'); | |
| 62 return FALSE; | |
| 63 } | |
| 64 $err = FALSE; | |
| 65 $success[] = 'SELECT'; | |
| 66 $success[] = 'CREATE'; | |
| 67 | |
| 68 // Test INSERT. | |
| 69 $query = 'INSERT INTO drupal_install_test (id) VALUES (1)'; | |
| 70 $result = pg_query($connection, $query); | |
| 71 if ($error = pg_result_error($result)) { | |
| 72 drupal_set_message(st('Failed to insert a value into a test table on your PostgreSQL database server. We tried inserting a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error'); | |
| 73 $err = TRUE; | |
| 74 } | |
| 75 else { | |
| 76 $success[] = 'INSERT'; | |
| 77 } | |
| 78 | |
| 79 // Test UPDATE. | |
| 80 $query = 'UPDATE drupal_install_test SET id = 2'; | |
| 81 $result = pg_query($connection, $query); | |
| 82 if ($error = pg_result_error($result)) { | |
| 83 drupal_set_message(st('Failed to update a value in a test table on your PostgreSQL database server. We tried updating a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error'); | |
| 84 $err = TRUE; | |
| 85 } | |
| 86 else { | |
| 87 $success[] = 'UPDATE'; | |
| 88 } | |
| 89 | |
| 90 // Test LOCK. | |
| 91 $query = 'BEGIN; LOCK drupal_install_test IN SHARE ROW EXCLUSIVE MODE'; | |
| 92 $result = pg_query($connection, $query); | |
| 93 if ($error = pg_result_error($result)) { | |
| 94 drupal_set_message(st('Failed to lock a test table on your PostgreSQL database server. We tried locking a table with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error'); | |
| 95 $err = TRUE; | |
| 96 } | |
| 97 else { | |
| 98 $success[] = 'LOCK'; | |
| 99 } | |
| 100 | |
| 101 // Test UNLOCK, which is done automatically upon transaction end in PostgreSQL | |
| 102 $query = 'COMMIT'; | |
| 103 $result = pg_query($connection, $query); | |
| 104 if ($error = pg_result_error()) { | |
| 105 drupal_set_message(st('Failed to unlock a test table on your PostgreSQL database server. We tried unlocking a table with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error'); | |
| 106 $err = TRUE; | |
| 107 } | |
| 108 else { | |
| 109 $success[] = 'UNLOCK'; | |
| 110 } | |
| 111 | |
| 112 // Test DELETE. | |
| 113 $query = 'DELETE FROM drupal_install_test'; | |
| 114 $result = pg_query($connection, $query); | |
| 115 if ($error = pg_result_error()) { | |
| 116 drupal_set_message(st('Failed to delete a value from a test table on your PostgreSQL database server. We tried deleting a value with the command %query and PostgreSQL reported the following error: %error.', array('%query' => $query, '%error' => $error)), 'error'); | |
| 117 $err = TRUE; | |
| 118 } | |
| 119 else { | |
| 120 $success[] = 'DELETE'; | |
| 121 } | |
| 122 | |
| 123 // Test DROP. | |
| 124 $query = 'DROP TABLE drupal_install_test'; | |
| 125 $result = pg_query($connection, $query); | |
| 126 if ($error = pg_result_error()) { | |
| 127 drupal_set_message(st('Failed to drop a test table from your PostgreSQL database server. We tried dropping a table with the command %query and PostgreSQL reported the following error %error.', array('%query' => $query, '%error' => $error)), 'error'); | |
| 128 $err = TRUE; | |
| 129 } | |
| 130 else { | |
| 131 $success[] = 'DROP'; | |
| 132 } | |
| 133 | |
| 134 if ($err) { | |
| 135 return FALSE; | |
| 136 } | |
| 137 | |
| 138 pg_close($connection); | |
| 139 return TRUE; | |
| 140 } |
