[ Index ] |
|
Code source de Drupal 5.3 |
1 <?php 2 // $Id: install.pgsql.inc,v 1.2 2006/12/27 13:02:34 drumm 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 30 // Decode url-encoded information in the db connection string. 31 $url['user'] = urldecode($url['user']); 32 $url['pass'] = urldecode($url['pass']); 33 $url['host'] = urldecode($url['host']); 34 $url['path'] = urldecode($url['path']); 35 36 // Build pgsql connection string and allow for non-standard PostgreSQL port. 37 $conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host']; 38 $conn_string .= isset($url['port']) ? ' port=' . $url['port'] : ''; 39 40 // Test connecting to the database. 41 $connection = @pg_connect($conn_string); 42 if (!$connection) { 43 drupal_set_message(st('Failure 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'); 44 return FALSE; 45 } 46 47 $success = array('CONNECT'); 48 49 // Test CREATE. 50 $query = 'CREATE TABLE drupal_install_test (id integer NOT NULL)'; 51 $result = pg_query($connection, $query); 52 if ($error = pg_result_error($result)) { 53 drupal_set_message(st('We were unable 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'); 54 return FALSE; 55 } 56 $err = FALSE; 57 $success[] = 'SELECT'; 58 $success[] = 'CREATE'; 59 60 // Test INSERT. 61 $query = 'INSERT INTO drupal_install_test (id) VALUES (1)'; 62 $result = pg_query($connection, $query); 63 if ($error = pg_result_error($result)) { 64 drupal_set_message(st('We were unable 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'); 65 $err = TRUE; 66 } 67 else { 68 $success[] = 'INSERT'; 69 } 70 71 // Test UPDATE. 72 $query = 'UPDATE drupal_install_test SET id = 2'; 73 $result = pg_query($connection, $query); 74 if ($error = pg_result_error($result)) { 75 drupal_set_message(st('We were unable 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'); 76 $err = TRUE; 77 } 78 else { 79 $success[] = 'UPDATE'; 80 } 81 82 // Test LOCK. 83 $query = 'BEGIN; LOCK drupal_install_test IN SHARE ROW EXCLUSIVE MODE'; 84 $result = pg_query($connection, $query); 85 if ($error = pg_result_error($result)) { 86 drupal_set_message(st('We were unable 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'); 87 $err = TRUE; 88 } 89 else { 90 $success[] = 'LOCK'; 91 } 92 93 // Test UNLOCK, which is done automatically upon transaction end in PostgreSQL 94 $query = 'COMMIT'; 95 $result = pg_query($connection, $query); 96 if ($error = pg_result_error()) { 97 drupal_set_message(st('We were unable 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'); 98 $err = TRUE; 99 } 100 else { 101 $success[] = 'UNLOCK'; 102 } 103 104 // Test DELETE. 105 $query = 'DELETE FROM drupal_install_test'; 106 $result = pg_query($connection, $query); 107 if ($error = pg_result_error()) { 108 drupal_set_message(st('We were unable 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'); 109 $err = TRUE; 110 } 111 else { 112 $success[] = 'DELETE'; 113 } 114 115 // Test DROP. 116 $query = 'DROP TABLE drupal_install_test'; 117 $result = pg_query($connection, $query); 118 if ($error = pg_result_error()) { 119 drupal_set_message(st('We were unable 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'); 120 $err = TRUE; 121 } 122 else { 123 $success[] = 'DROP'; 124 } 125 126 if ($err) { 127 return FALSE; 128 } 129 130 pg_close($connection); 131 return TRUE; 132 } 133 134 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Nov 30 16:20:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |