BxDevDb.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <? 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. function __construct(&$oConfig) {
  14. parent::__construct($oConfig);
  15. }
  16. function getQueryInsert($sTable, $aItems, $mixedComment = false, $aExclude = array('id')) {
  17. bx_import('BxDevFunctions');
  18. $bFirst = true;
  19. $sContent = $sComment = "";
  20. foreach($aItems as $aItem) {
  21. foreach($aExclude as $sKey)
  22. if(isset($aItem[$sKey]))
  23. unset($aItem[$sKey]);
  24. $aKeys = array_keys($aItem);
  25. $aValues = array_values($aItem);
  26. $iValues = count($aValues);
  27. bx_import('BxDevFunctions');
  28. foreach ($aValues as $iKey => $sValue)
  29. $aValues[$iKey] = BxDevFunctions::dbAddSlashes($sValue, true);
  30. if($bFirst) {
  31. $sContent .= "INSERT INTO `" . $sTable . "`(`" . implode("`, `", $aKeys) . "`) VALUES \n";
  32. $bFirst = false;
  33. }
  34. $sSql = "(" . implode(", ", array_fill(0, $iValues, "?")) . "),\n";
  35. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), $aValues));
  36. $sContent .= $sSql;
  37. }
  38. $sContent = substr($sContent, 0, -2) . ";\n\n";
  39. if($mixedComment === true || (is_string($mixedComment) && $mixedComment != ''))
  40. $sComment = "--\n-- " . ($mixedComment === true ? "Dumping data for table `" . $sTable . "`" : $mixedComment) . "\n--\n";
  41. return $sComment . $sContent;
  42. }
  43. function getQueryDelete($sTable, $sKey, $aItems, $mixedComment = false) {
  44. $sContent = $sComment = "";
  45. foreach($aItems as $aItem)
  46. if(isset($aItem[$sKey])) {
  47. $sSql = "DELETE FROM `" . $sTable . "` WHERE `" . $sKey . "`=?;\n";
  48. $sContent .= call_user_func_array(array($this, 'prepare'), array($sSql, $aItem[$sKey]));
  49. }
  50. $sContent .= "\n";
  51. if($mixedComment === true || (is_string($mixedComment) && $mixedComment != ''))
  52. $sComment = "--\n-- " . ($mixedComment === true ? "Delete data from table `" . $sTable . "`" : $mixedComment) . "\n--\n";
  53. return $sComment . $sContent;
  54. }
  55. }
  56. /** @} */