BxDevDb.php 2.4 KB

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