mysql.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. $config = parse_ini_file(dirname(__FILE__)."/config");
  3. $dbport = (empty($config['port'])) ? 3306 : $config['port'];
  4. if (extension_loaded('mysqli')) {
  5. $loginDB = new mysqli($config['host'], $config['username'], $config['password'], $config['database'], $dbport);
  6. function DB_query($query) {
  7. global $loginDB;
  8. $result = $loginDB->query($query);
  9. return($result);
  10. }
  11. function DB_real_escape_string($parametr) {
  12. global $loginDB;
  13. $result = $loginDB->real_escape_string($parametr);
  14. return($result);
  15. }
  16. function DB_fetch_array($data) {
  17. $result = mysqli_fetch_assoc($data);
  18. return($result);
  19. }
  20. } else {
  21. $link = mysql_connect($config['host'] . ':' . $dbport, $config['username'], $config['password']);
  22. mysql_select_db($config['database']);
  23. function DB_query($query) {
  24. $result = mysql_query($query);
  25. return($result);
  26. }
  27. function DB_real_escape_string($parametr) {
  28. $result = mysql_real_escape_string($parametr);
  29. return($result);
  30. }
  31. function DB_fetch_array($data) {
  32. $result = mysql_fetch_array($data, MYSQL_ASSOC);
  33. return($result);
  34. }
  35. }
  36. ?>