functions.core.db.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* $Id: functions.core.db.php 3304 2007-12-09 14:33:13Z warion $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. /**
  16. * ADOdb
  17. */
  18. require_once('inc/lib/adodb/adodb.inc.php');
  19. /**
  20. * initialize ADOdb-connection
  21. */
  22. function dbInitialize() {
  23. global $cfg, $db;
  24. // create ado-object
  25. $db = ADONewConnection($cfg["db_type"]);
  26. // connect
  27. if ($cfg["db_pcon"])
  28. $result = @ $db->PConnect($cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  29. else
  30. $result = @ $db->Connect($cfg["db_host"], $cfg["db_user"], $cfg["db_pass"], $cfg["db_name"]);
  31. // register shutdown-function
  32. @register_shutdown_function("dbDispose");
  33. // check for error
  34. if ($db->ErrorNo() != 0 || !$result)
  35. @error("Database Connection Problems", "", "", array("Check your database-config-file. (inc/config/config.db.php)"));
  36. }
  37. /**
  38. * dispose ADOdb-connection
  39. */
  40. function dbDispose() {
  41. global $db;
  42. // close connection
  43. @ $db->Close();
  44. }
  45. /**
  46. * db-error-function
  47. *
  48. * @param $sql
  49. */
  50. function dbError($sql) {
  51. global $cfg, $db;
  52. $msgs = array();
  53. $dbErrMsg = $db->ErrorMsg();
  54. array_push($msgs, "ErrorMsg : ");
  55. array_push($msgs, $dbErrMsg);
  56. if ($cfg["debug_sql"] != 0) {
  57. array_push($msgs, "\nSQL : ");
  58. array_push($msgs, $sql);
  59. }
  60. array_push($msgs, "");
  61. if (preg_match('/.*Query.*empty.*/i', $dbErrMsg))
  62. array_push($msgs, "\nDatabase may be corrupted. Try to repair the tables.");
  63. else
  64. array_push($msgs, "\nAlways check your database settings in the config.db.php file.");
  65. @error("Database-Error", "", "", $msgs);
  66. }
  67. ?>