[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/install/includes/functions/ -> database.php (source)

   1  <?php
   2  /*

   3  $Id: database.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13    function osc_db_connect($server, $username, $password, $link = 'db_link') {
  14      global $$link, $db_error;
  15  
  16      $db_error = false;
  17  
  18      if (!$server) {
  19        $db_error = 'No Server selected.';
  20        return false;
  21      }
  22  
  23      $$link = @mysql_connect($server, $username, $password) or $db_error = mysql_error();
  24  
  25      return $$link;
  26    }
  27  
  28    function osc_db_select_db($database) {
  29      return mysql_select_db($database);
  30    }
  31  
  32    function osc_db_query($query, $link = 'db_link') {
  33      global $$link;
  34  
  35      return mysql_query($query, $$link);
  36    }
  37  
  38    function osc_db_num_rows($db_query) {
  39      return mysql_num_rows($db_query);
  40    }
  41  
  42    function osc_db_install($database, $sql_file) {
  43      global $db_error;
  44  
  45      $db_error = false;
  46  
  47      if ([email protected]osc_db_select_db($database)) {
  48        if (@osc_db_query('create database ' . $database)) {
  49          osc_db_select_db($database);
  50        } else {
  51          $db_error = mysql_error();
  52        }
  53      }
  54  
  55      if (!$db_error) {
  56        if (file_exists($sql_file)) {
  57          $fd = fopen($sql_file, 'rb');
  58          $restore_query = fread($fd, filesize($sql_file));
  59          fclose($fd);
  60        } else {
  61          $db_error = 'SQL file does not exist: ' . $sql_file;
  62          return false;
  63        }
  64  
  65        $sql_array = array();
  66        $sql_length = strlen($restore_query);
  67        $pos = strpos($restore_query, ';');
  68        for ($i=$pos; $i<$sql_length; $i++) {
  69          if ($restore_query[0] == '#') {
  70            $restore_query = ltrim(substr($restore_query, strpos($restore_query, "\n")));
  71            $sql_length = strlen($restore_query);
  72            $i = strpos($restore_query, ';')-1;
  73            continue;
  74          }
  75          if ($restore_query[($i+1)] == "\n") {
  76            for ($j=($i+2); $j<$sql_length; $j++) {
  77              if (trim($restore_query[$j]) != '') {
  78                $next = substr($restore_query, $j, 6);
  79                if ($next[0] == '#') {
  80  // find out where the break position is so we can remove this line (#comment line)

  81                  for ($k=$j; $k<$sql_length; $k++) {
  82                    if ($restore_query[$k] == "\n") break;
  83                  }
  84                  $query = substr($restore_query, 0, $i+1);
  85                  $restore_query = substr($restore_query, $k);
  86  // join the query before the comment appeared, with the rest of the dump

  87                  $restore_query = $query . $restore_query;
  88                  $sql_length = strlen($restore_query);
  89                  $i = strpos($restore_query, ';')-1;
  90                  continue 2;
  91                }
  92                break;
  93              }
  94            }
  95            if ($next == '') { // get the last insert query
  96              $next = 'insert';
  97            }
  98            if ( (eregi('create', $next)) || (eregi('insert', $next)) || (eregi('drop t', $next)) ) {
  99              $next = '';
 100              $sql_array[] = substr($restore_query, 0, $i);
 101              $restore_query = ltrim(substr($restore_query, $i+1));
 102              $sql_length = strlen($restore_query);
 103              $i = strpos($restore_query, ';')-1;
 104            }
 105          }
 106        }
 107  
 108        osc_db_query("drop table if exists address_book, address_format, administrators, banners, banners_history, categories, categories_description, configuration, configuration_group, counter, counter_history, countries, currencies, customers, customers_basket, customers_basket_attributes, customers_info, languages, manufacturers, manufacturers_info, orders, orders_products, orders_status, orders_status_history, orders_products_attributes, orders_products_download, products, products_attributes, products_attributes_download, prodcts_description, products_options, products_options_values, products_options_values_to_products_options, products_to_categories, reviews, reviews_description, sessions, specials, tax_class, tax_rates, geo_zones, whos_online, zones, zones_to_geo_zones");
 109  
 110        for ($i=0; $i<sizeof($sql_array); $i++) {
 111          osc_db_query($sql_array[$i]);
 112        }
 113      } else {
 114        return false;
 115      }
 116    }
 117  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7