[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

   1  <?php
   2  
   3  // MySQLi specific install functions
   4  
   5  /**
   6   * Check if MySQLi is available.
   7   *
   8   * @return
   9   *  TRUE/FALSE
  10   */
  11  function mysqli_is_available() {
  12    return function_exists('mysqli_connect');
  13  }
  14  
  15  /**
  16   * Check if we can connect to MySQL.
  17   *
  18   * @return
  19   *  TRUE/FALSE
  20   */
  21  function drupal_test_mysqli($url, &$success) {
  22    if (!mysqli_is_available()) {
  23      drupal_set_message(st('PHP MySQLi support not enabled.'), 'error');
  24      return FALSE;
  25    }
  26  
  27    $url = parse_url($url);
  28  
  29    // Decode url-encoded information in the db connection string.
  30    $url['user'] = urldecode($url['user']);
  31    $url['pass'] = isset($url['pass']) ? urldecode($url['pass']) : '';
  32    $url['host'] = urldecode($url['host']);
  33    $url['path'] = urldecode($url['path']);
  34  
  35    $connection = mysqli_init();
  36    @mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS);
  37    if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) {
  38      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');
  39      return FALSE;
  40    }
  41  
  42    // Test selecting the database.
  43    if (mysqli_connect_errno() > 0) {
  44      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');
  45      return FALSE;
  46    }
  47  
  48    $success = array('CONNECT');
  49  
  50    // Test CREATE.
  51    $query = 'CREATE TABLE drupal_install_test (id int NULL)';
  52    $result = mysqli_query($connection, $query);
  53    if ($error = mysqli_error($connection)) {
  54      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');
  55      return FALSE;
  56    }
  57    $err = FALSE;
  58    $success[] = 'SELECT';
  59    $success[] = 'CREATE';
  60  
  61    // Test INSERT.
  62    $query = 'INSERT INTO drupal_install_test (id) VALUES (1)';
  63    $result = mysqli_query($connection, $query);
  64    if ($error = mysqli_error($connection)) {
  65      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');
  66      $err = TRUE;
  67    }
  68    else {
  69      $success[] = 'INSERT';
  70    }
  71  
  72    // Test UPDATE.
  73    $query = 'UPDATE drupal_install_test SET id = 2';
  74    $result = mysqli_query($connection, $query);
  75    if ($error = mysqli_error($connection)) {
  76      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');
  77      $err = TRUE;
  78    }
  79    else {
  80      $success[] = 'UPDATE';
  81    }
  82  
  83    // Test DELETE.
  84    $query = 'DELETE FROM drupal_install_test';
  85    $result = mysqli_query($connection, $query);
  86    if ($error = mysqli_error($connection)) {
  87      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');
  88      $err = TRUE;
  89    }
  90    else {
  91      $success[] = 'DELETE';
  92    }
  93  
  94    // Test DROP.
  95    $query = 'DROP TABLE drupal_install_test';
  96    $result = mysqli_query($connection, $query);
  97    if ($error = mysqli_error($connection)) {
  98      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');
  99      $err = TRUE;
 100    }
 101    else {
 102      $success[] = 'DROP';
 103    }
 104  
 105    if ($err) {
 106      return FALSE;
 107    }
 108  
 109    mysqli_close($connection);
 110    return TRUE;
 111  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7