[ Index ]
 

Code source de Drupal 5.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/ -> install.mysqli.inc (source)

   1  <?php
   2  // $Id: install.mysqli.inc,v 1.6 2006/12/27 13:02:34 drumm 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'] = 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('Failure 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_error($connection))), 'error');
  40      return FALSE;
  41    }
  42  
  43    // Test selecting the database.
  44    if (mysqli_connect_errno() > 0) {
  45      drupal_set_message(st('We were able to connect to the MySQL database server (which means your username and password are valid) but not able to select your database. 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_error($connection))), '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('We were unable 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('We were unable 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('We were unable 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 LOCK.
  85    $query = 'LOCK TABLES drupal_install_test WRITE';
  86    $result = mysqli_query($connection, $query);
  87    if ($error = mysqli_error($connection)) {
  88      drupal_set_message(st('We were unable to lock a test table on your MySQL database server. We tried locking a table 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[] = 'LOCK';
  93    }
  94  
  95    // Test UNLOCK.
  96    $query = 'UNLOCK TABLES';
  97    $result = mysqli_query($connection, $query);
  98    if ($error = mysqli_error($connection)) {
  99      drupal_set_message(st('We were unable to unlock a test table on your MySQL database server. We tried unlocking 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[] = 'UNLOCK';
 104    }
 105  
 106    // Test DELETE.
 107    $query = 'DELETE FROM drupal_install_test';
 108    $result = mysqli_query($connection, $query);
 109    if ($error = mysqli_error($connection)) {
 110      drupal_set_message(st('We were unable 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');
 111      $err = TRUE;
 112    }
 113    else {
 114      $success[] = 'DELETE';
 115    }
 116  
 117    // Test DROP.
 118    $query = 'DROP TABLE drupal_install_test';
 119    $result = mysqli_query($connection, $query);
 120    if ($error = mysqli_error($connection)) {
 121      drupal_set_message(st('We were unable 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');
 122      $err = TRUE;
 123    }
 124    else {
 125      $success[] = 'DROP';
 126    }
 127  
 128    if ($err) {
 129      return FALSE;
 130    }
 131  
 132    mysqli_close($connection);
 133    return TRUE;
 134  }
 135  
 136  ?>


Généré le : Fri Nov 30 16:20:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics