国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.3KB

  1. <?php
  2. /**
  3. * 数据库操作替换
  4. *
  5. * @version $Id: sys_data_replace.php 1 22:28 2010年7月20日Z tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__) . '/config.php');
  12. CheckPurview('sys_Data');
  13. if (empty($action)) $action = '';
  14. if (empty($action)) {
  15. require_once(DEDEADMIN . "/templets/sys_data_replace.htm");
  16. exit();
  17. }
  18. /*-------------------------------
  19. //列出数据库表里的字段
  20. function __getfields()
  21. --------------------------------*/ else if ($action == 'getfields') {
  22. AjaxHead();
  23. $dsql->GetTableFields($exptable);
  24. echo "<div style='border:1px solid #ababab;background-color:#FEFFF0;margin-top:6px;padding:3px;line-height:160%'>";
  25. echo "表(" . $exptable . ")含有的字段:<br>";
  26. while ($row = $dsql->GetFieldObject()) {
  27. echo "<a href=\"javascript:pf('{$row->name}')\"><u>" . $row->name . "</u></a>\r\n";
  28. }
  29. echo "</div>";
  30. exit();
  31. }
  32. /*-------------------------------
  33. //保存用户设置,清空会员数据
  34. function __Apply()
  35. --------------------------------*/ else if ($action == 'apply') {
  36. $validate = empty($validate) ? '' : strtolower($validate);
  37. $svali = GetCkVdValue();
  38. if ($validate == "" || $validate != $svali) {
  39. ShowMsg("安全确认码不正确!", "javascript:;");
  40. exit();
  41. }
  42. if ($exptable == '' || $rpfield == '') {
  43. ShowMsg("请指定数据表和字段!", "javascript:;");
  44. exit();
  45. }
  46. if ($rpstring == '') {
  47. ShowMsg("请指定被替换内容!", "javascript:;");
  48. exit();
  49. }
  50. if ($rptype == 'replace') {
  51. $condition = empty($condition) ? '' : " WHERE $condition ";
  52. $rs = $dsql->ExecuteNoneQuery("UPDATE $exptable SET $rpfield=REPLACE($rpfield,'$rpstring','$tostring') $condition ");
  53. $dsql->ExecuteNoneQuery("OPTIMIZE TABLE `$exptable`");
  54. if ($rs) {
  55. ShowMsg("成功完成数据替换!", "javascript:;");
  56. exit();
  57. } else {
  58. ShowMsg("数据替换失败!", "javascript:;");
  59. exit();
  60. }
  61. } else {
  62. $condition = empty($condition) ? '' : " And $condition ";
  63. $rpstring = stripslashes($rpstring);
  64. $rpstring2 = str_replace("\\", "\\\\", $rpstring);
  65. $rpstring2 = str_replace("'", "\\'", $rpstring2);
  66. $dsql->SetQuery("SELECT $keyfield,$rpfield FROM $exptable WHERE $rpfield REGEXP '$rpstring2' $condition ");
  67. $dsql->Execute();
  68. $tt = $dsql->GetTotalRow();
  69. if ($tt == 0) {
  70. ShowMsg("根据你指定的正则,找不到任何东西!", "javascript:;");
  71. exit();
  72. }
  73. $oo = 0;
  74. while ($row = $dsql->GetArray()) {
  75. $kid = $row[$keyfield];
  76. $rpf = preg_replace("#" . $rpstring . "#i", $tostring, $row[$rpfield]);
  77. $rs = $dsql->ExecuteNoneQuery("UPDATE $exptable SET $rpfield='$rpf' WHERE $keyfield='$kid' ");
  78. if ($rs) {
  79. $oo++;
  80. }
  81. }
  82. $dsql->ExecuteNoneQuery("OPTIMIZE TABLE `$exptable`");
  83. ShowMsg("共找到 $tt 条记录,成功替换了 $oo 条!", "javascript:;");
  84. exit();
  85. }
  86. }