PDO::ERRMODE_WARNING, // Leave column names as returned by the database driver. PDO::ATTR_CASE => PDO::CASE_NATURAL, ); try { $connection = new PDO($dsn, $username, $password, $driver_options); } catch (PDOExecption $e) { drupal_set_message(st('Failed to connect to your PostgreSQL database server. PostgreSQL reports the following message: %error.For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%error' => $e->getMessage())), 'error'); return FALSE; } $success = array('CONNECT'); // Test CREATE. $query = 'CREATE TABLE "drupal_install_test" ("id" INT NOT NULL)'; $stmt = $connection->prepare($query); $stmt->execute(); $error = $stmt->errorInfo(); if (is_array($error) && $error[0] != 0 && isset($error[2])) { 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.For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.', array('%query' => $query, '%error' => $error[2])), 'error'); return FALSE; } $err = FALSE; $success[] = 'SELECT'; $success[] = 'CREATE'; // Test INSERT. $query = 'INSERT INTO "drupal_install_test" ("id") VALUES (1)'; $stmt = $connection->prepare($query); $stmt->execute(); $error = $stmt->errorInfo(); if (is_array($error) && $error[0] != 0 && isset($error[2])) { 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[2])), 'error'); $err = TRUE; } else { $success[] = 'INSERT'; } // Test UPDATE. $query = 'UPDATE "drupal_install_test" SET "id" = 2'; $stmt = $connection->prepare($query); $stmt->execute(); $error = $stmt->errorInfo(); if (is_array($error) && $error[0] != 0 && isset($error[2])) { 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[2])), 'error'); $err = TRUE; } else { $success[] = 'UPDATE'; } // Test LOCK. $query = 'LOCK "drupal_install_test" IN SHARE ROW EXCLUSIVE MODE'; $stmt = $connection->prepare($query); $stmt->execute(); $error = $stmt->errorInfo(); if (is_array($error) && $error[0] != 0 && isset($error[2])) { 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[2])), 'error'); $err = TRUE; } else { $success[] = 'LOCK'; } // Test UNLOCK, which is done automatically upon transaction end in PostgreSQL. $query = 'COMMIT'; $stmt = $connection->prepare($query); $stmt->execute(); $error = $stmt->errorInfo(); if (is_array($error) && $error[0] != 0 && isset($error[2])) { 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[2])), 'error'); $err = TRUE; } else { $success[] = 'UNLOCK'; } // Test DELETE. $query = 'DELETE FROM "drupal_install_test"'; $stmt = $connection->prepare($query); $stmt->execute(); $error = $stmt->errorInfo(); if (is_array($error) && $error[0] != 0 && isset($error[2])) { 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[2])), 'error'); $err = TRUE; } else { $success[] = 'DELETE'; } // Test DROP. $query = 'DROP TABLE "drupal_install_test"'; $stmt = $connection->prepare($query); $stmt->execute(); $error = $stmt->errorInfo(); if (is_array($error) && $error[0] != 0 && isset($error[2])) { 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[2])), 'error'); $err = TRUE; } else { $success[] = 'DROP'; } if ($err) { return FALSE; } $connection = NULL; return TRUE; }