osCommerce PHP Cross Reference Customer Relationship Management

Source: /includes/functions/database.php - 266 lines - 6769 bytes - Summary - Text - Print

   1  <?php
   2  /*
   3    $Id$
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2013 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {
  14      global $$link;
  15  
  16      if (USE_PCONNECT == 'true') {
  17        $server = 'p:' . $server;
  18      }
  19  
  20      $$link = mysqli_connect($server, $username, $password, $database);
  21  
  22      if ( !mysqli_connect_errno() ) {
  23        mysqli_set_charset($$link, 'utf8');
  24      } 
  25  
  26      return $$link;
  27    }
  28  
  29    function tep_db_close($link = 'db_link') {
  30      global $$link;
  31  
  32      return mysqli_close($$link);
  33    }
  34  
  35    function tep_db_error($query, $errno, $error) { 
  36      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
  37        error_log('ERROR: [' . $errno . '] ' . $error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
  38      }
  39  
  40      die('<font color="#000000"><strong>' . $errno . ' - ' . $error . '<br /><br />' . $query . '<br /><br /><small><font color="#ff0000">[TEP STOP]</font></small><br /><br /></strong></font>');
  41    }
  42  
  43    function tep_db_query($query, $link = 'db_link') {
  44      global $$link;
  45  
  46      if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
  47        error_log('QUERY: ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
  48      }
  49  
  50      $result = mysqli_query($$link, $query) or tep_db_error($query, mysqli_errno($$link), mysqli_error($$link));
  51  
  52      return $result;
  53    }
  54  
  55    function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
  56      reset($data);
  57      if ($action == 'insert') {
  58        $query = 'insert into ' . $table . ' (';
  59        while (list($columns, ) = each($data)) {
  60          $query .= $columns . ', ';
  61        }
  62        $query = substr($query, 0, -2) . ') values (';
  63        reset($data);
  64        while (list(, $value) = each($data)) {
  65          switch ((string)$value) {
  66            case 'now()':
  67              $query .= 'now(), ';
  68              break;
  69            case 'null':
  70              $query .= 'null, ';
  71              break;
  72            default:
  73              $query .= '\'' . tep_db_input($value) . '\', ';
  74              break;
  75          }
  76        }
  77        $query = substr($query, 0, -2) . ')';
  78      } elseif ($action == 'update') {
  79        $query = 'update ' . $table . ' set ';
  80        while (list($columns, $value) = each($data)) {
  81          switch ((string)$value) {
  82            case 'now()':
  83              $query .= $columns . ' = now(), ';
  84              break;
  85            case 'null':
  86              $query .= $columns .= ' = null, ';
  87              break;
  88            default:
  89              $query .= $columns . ' = \'' . tep_db_input($value) . '\', ';
  90              break;
  91          }
  92        }
  93        $query = substr($query, 0, -2) . ' where ' . $parameters;
  94      }
  95  
  96      return tep_db_query($query, $link);
  97    }
  98  
  99    function tep_db_fetch_array($db_query) {
 100      return mysqli_fetch_array($db_query, MYSQLI_ASSOC);
 101    }
 102  
 103    function tep_db_num_rows($db_query) {
 104      return mysqli_num_rows($db_query);
 105    }
 106  
 107    function tep_db_data_seek($db_query, $row_number) {
 108      return mysqli_data_seek($db_query, $row_number);
 109    }
 110  
 111    function tep_db_insert_id($link = 'db_link') {
 112      global $$link;
 113  
 114      return mysqli_insert_id($$link);
 115    }
 116  
 117    function tep_db_free_result($db_query) {
 118      return mysqli_free_result($db_query);
 119    }
 120  
 121    function tep_db_fetch_fields($db_query) {
 122      return mysqli_fetch_field($db_query);
 123    }
 124  
 125    function tep_db_output($string) {
 126      return htmlspecialchars($string);
 127    }
 128  
 129    function tep_db_input($string, $link = 'db_link') {
 130      global $$link;
 131  
 132      return mysqli_real_escape_string($$link, $string);
 133    }
 134  
 135    function tep_db_prepare_input($string) {
 136      if (is_string($string)) {
 137        return trim(tep_sanitize_string(stripslashes($string)));
 138      } elseif (is_array($string)) {
 139        reset($string);
 140        while (list($key, $value) = each($string)) {
 141          $string[$key] = tep_db_prepare_input($value);
 142        }
 143        return $string;
 144      } else {
 145        return $string;
 146      }
 147    }
 148  
 149    function tep_db_affected_rows($link = 'db_link') {
 150      global $$link;
 151  
 152      return mysqli_affected_rows($$link);
 153    }
 154  
 155    function tep_db_get_server_info($link = 'db_link') {
 156      global $$link;
 157  
 158      return mysqli_get_server_info($$link);
 159    }
 160  
 161    if ( !function_exists('mysqli_connect') ) {
 162      define('MYSQLI_ASSOC', MYSQL_ASSOC);
 163  
 164      function mysqli_connect($server, $username, $password, $database) {
 165        if ( substr($server, 0, 2) == 'p:' ) {
 166          $link = mysql_pconnect(substr($server, 2), $username, $password);
 167        } else {
 168          $link = mysql_connect($server, $username, $password);
 169        }
 170  
 171        if ( $link ) {
 172          mysql_select_db($database, $link);
 173        }
 174  
 175        return $link;
 176      }
 177  
 178      function mysqli_connect_errno($link = null) {
 179        if ( is_null($link) ) {
 180          return mysql_errno();
 181        }
 182  
 183        return mysql_errno($link);
 184      }
 185  
 186      function mysqli_connect_error($link = null) {
 187        if ( is_null($link) ) {
 188          return mysql_error();
 189        }
 190  
 191        return mysql_error($link);
 192      }
 193  
 194      function mysqli_set_charset($link, $charset) {
 195        if ( function_exists('mysql_set_charset') ) {
 196          return mysql_set_charset($charset, $link);
 197        }
 198      }
 199  
 200      function mysqli_close($link) {
 201        return mysql_close($link);
 202      }
 203  
 204      function mysqli_query($link, $query) {
 205        return mysql_query($query, $link);
 206      }
 207  
 208      function mysqli_errno($link = null) {
 209        if ( is_null($link) ) {
 210          return mysql_errno();
 211        }
 212  
 213        return mysql_errno($link);
 214      }
 215  
 216      function mysqli_error($link = null) {
 217        if ( is_null($link) ) {
 218          return mysql_error();
 219        }
 220  
 221        return mysql_error($link);
 222      }
 223  
 224      function mysqli_fetch_array($query, $type) {
 225        return mysql_fetch_array($query, $type);
 226      }
 227  
 228      function mysqli_num_rows($query) {
 229        return mysql_num_rows($query);
 230      }
 231  
 232      function mysqli_data_seek($query, $offset) {
 233        return mysql_data_seek($query, $offset);
 234      }
 235  
 236      function mysqli_insert_id($link) {
 237        return mysql_insert_id($link);
 238      }
 239  
 240      function mysqli_free_result($query) {
 241        return mysql_free_result($query);
 242      }
 243  
 244      function mysqli_fetch_field($query) {
 245        return mysql_fetch_field($query);
 246      }
 247  
 248      function mysqli_real_escape_string($link, $string) {
 249        if ( function_exists('mysql_real_escape_string') ) {
 250          return mysql_real_escape_string($string, $link);
 251        } elseif ( function_exists('mysql_escape_string') ) {
 252          return mysql_escape_string($string);
 253        }
 254  
 255        return addslashes($string);
 256      }
 257  
 258      function mysqli_affected_rows($link) {
 259        return mysql_affected_rows($link);
 260      }
 261  
 262      function mysqli_get_server_info($link) {
 263        return mysql_get_server_info($link);
 264      }
 265    }
 266  ?>

title

Description

title

Description

title

Description

title

title

Body