BxDevDb.php 2.2 KB

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