BxDevDb.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Developer Developer
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModuleDb');
  12. class BxDevDb extends BxDolModuleDb
  13. {
  14. function __construct(&$oConfig)
  15. {
  16. parent::__construct($oConfig);
  17. }
  18. function getQueryInsert($sTable, $aItems, $mixedComment = false, $aExclude = array('id'))
  19. {
  20. bx_import('BxDevFunctions');
  21. $bFirst = true;
  22. $sContent = $sComment = "";
  23. foreach($aItems as $aItem) {
  24. foreach($aExclude as $sKey)
  25. if(isset($aItem[$sKey]))
  26. unset($aItem[$sKey]);
  27. $aKeys = array_keys($aItem);
  28. $aValues = array_values($aItem);
  29. $iValues = count($aValues);
  30. bx_import('BxDevFunctions');
  31. foreach ($aValues as $iKey => $sValue)
  32. $aValues[$iKey] = BxDevFunctions::dbAddSlashes($sValue, true);
  33. if($bFirst) {
  34. $sContent .= "INSERT INTO `" . $sTable . "`(`" . implode("`, `", $aKeys) . "`) VALUES \n";
  35. $bFirst = false;
  36. }
  37. $sSql = "(" . implode(", ", array_fill(0, $iValues, "?")) . "),\n";
  38. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), $aValues));
  39. $sContent .= $sSql;
  40. }
  41. $sContent = substr($sContent, 0, -2) . ";\n\n";
  42. if($mixedComment === true || (is_string($mixedComment) && $mixedComment != ''))
  43. $sComment = "--\n-- " . ($mixedComment === true ? "Dumping data for table `" . $sTable . "`" : $mixedComment) . "\n--\n";
  44. return $sComment . $sContent;
  45. }
  46. function getQueryDelete($sTable, $sKey, $aItems, $mixedComment = false)
  47. {
  48. $sContent = $sComment = "";
  49. foreach($aItems as $aItem)
  50. if(isset($aItem[$sKey])) {
  51. $sSql = "DELETE FROM `" . $sTable . "` WHERE `" . $sKey . "`=?;\n";
  52. $sContent .= call_user_func_array(array($this, 'prepare'), array($sSql, $aItem[$sKey]));
  53. }
  54. $sContent .= "\n";
  55. if($mixedComment === true || (is_string($mixedComment) && $mixedComment != ''))
  56. $sComment = "--\n-- " . ($mixedComment === true ? "Delete data from table `" . $sTable . "`" : $mixedComment) . "\n--\n";
  57. return $sComment . $sContent;
  58. }
  59. }
  60. /** @} */