修复数据库更新错误

This commit is contained in:
wlx 2011-10-18 05:02:55 +00:00
parent f61b0d450c
commit f45c9c9321
2 changed files with 26 additions and 23 deletions

View File

@ -8,6 +8,7 @@ class Admin_WatermdController extends Zend_Controller_Action
$this->messenger=$this->_helper->getHelper('FlashMessenger'); $this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages(); $this->view->messages = $this->messenger->getMessages();
$this->wdb=Zend_Db::factory($this->view->config->waterdb); $this->wdb=Zend_Db::factory($this->view->config->waterdb);
set_time_limit(0);
} }
function postDispatch() function postDispatch()
{ {
@ -303,23 +304,26 @@ class Admin_WatermdController extends Zend_Controller_Action
$this->view->test=$this->contactReplace($formdata["testxml"],$formdata); $this->view->test=$this->contactReplace($formdata["testxml"],$formdata);
} elseif (isset($formdata["submit"])) } elseif (isset($formdata["submit"]))
{ {
$sql="select uuid,data from metadata where istemplate = 'n'"; $sql="select uuid,data from metadata where istemplate = 'n' and data like '%".$formdata['oldname']."%'";
$rows=$this->wdb->fetchAll($sql); $rows=$this->wdb->fetchAll($sql);
foreach($rows as $k=>$row) $this->view->deal=array();
foreach($rows as $row)
{ {
//do the replace //do the replace
$new_data=$this->contactReplace($row["data"],$formdata); $new_data=$this->contactReplace($row["data"],$formdata);
//防止正则错误 //防止错误
if (!empty($new_data)) if (!empty($new_data))
{ {
$sql="update metadata set data=? where uuid=?"; $sql="update metadata set data=? where uuid='".$row['uuid']."'";
$this->wdb->query($sql,array($new_data,$uuid)); if ($this->wdb->exec($this->wdb->quoteInto($sql,$new_data)))
{
$dom = new DOMDocument(); $dom = new DOMDocument();
$dom->loadXML($row['data']); $dom->loadXML($row['data']);
$title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue; $title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
$deal['uuid']=$uuid; $deal['uuid']=$row['uuid'];
$deal['title']=$title; $deal['title']=$title;
$this->view->deal[]=$deal; $this->view->deal[]=$deal;
}
} }
} }
} }

View File

@ -23,19 +23,6 @@
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if ($this->deal) : ?>
<div id="mdlist">
已处理数据:
<?php foreach ($this->deal as $deal): ?>
<ul>
<li>UUID<?php echo $deal['uuid']; ?></li>
<li><a href="/heihe/<?= $deal['uuid']; ?>"><?= $deal['title']; ?></a></li>
</ul>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<form enctype="application/x-www-form-urlencoded" action="" method="post"> <form enctype="application/x-www-form-urlencoded" action="" method="post">
<label>被替换者姓名:</label> <label>被替换者姓名:</label>
<input type="text" name="oldname" value="<?= $this->formdata['oldname'] ?>"> <input type="text" name="oldname" value="<?= $this->formdata['oldname'] ?>">
@ -43,17 +30,29 @@
<li><label>姓名:</label><input type="text" name="name" value="<?= $this->formdata['name'] ?>"></li> <li><label>姓名:</label><input type="text" name="name" value="<?= $this->formdata['name'] ?>"></li>
<li><label>单位:</label><input type="text" name="unit" value="<?= $this->formdata['unit'] ?>"></li> <li><label>单位:</label><input type="text" name="unit" value="<?= $this->formdata['unit'] ?>"></li>
<li><label>地址:</label><input type="text" name="delpoint" value="<?= $this->formdata['delpoint'] ?>"></li> <li><label>地址:</label><input type="text" name="delpoint" value="<?= $this->formdata['delpoint'] ?>"></li>
<li><label>City</label><input type="text" name="city" value="<?= $this->formdata['city'] ?>"></li> <li><label>城市</label><input type="text" name="city" value="<?= $this->formdata['city'] ?>"></li>
<li><label>Province</label><input type="text" name="adminarea" value="<?= $this->formdata['adminarea'] ?>"></li> <li><label>省份</label><input type="text" name="adminarea" value="<?= $this->formdata['adminarea'] ?>"></li>
<li><label>Country</label><input type="text" name="country" value="<?= $this->formdata['country'] ?>"></li> <li><label>国家</label><input type="text" name="country" value="<?= $this->formdata['country'] ?>"></li>
<li><label>邮编:</label><input type="text" name="postcode" value="<?= $this->formdata['postcode'] ?>"></li> <li><label>邮编:</label><input type="text" name="postcode" value="<?= $this->formdata['postcode'] ?>"></li>
<li><label>电话:</label><input type="text" name="voicenum" value="<?= $this->formdata['voicenum'] ?>"></li> <li><label>电话:</label><input type="text" name="voicenum" value="<?= $this->formdata['voicenum'] ?>"></li>
<li><label>邮箱:</label><input type="text" name="email" value="<?= $this->formdata['email'] ?>"></li> <li><label>邮箱:</label><input type="text" name="email" value="<?= $this->formdata['email'] ?>"></li>
</fieldset> </fieldset>
<label>测试XML数据</label> <label>测试XML数据</label>
<textarea name="testxml" rows="10" cols="80"><?= $this->formdata['testxml'] ?></textarea> <textarea name="testxml" rows="10" cols="80"><?= $this->formdata['testxml'] ?></textarea>
<li><input type="submit" name="test" id="test" value="测试"> <input type="submit" name="submit" value="全部运行(危险操作!请先测试)"></li> <li><input type="submit" name="test" id="test" value="测试"> <input type="submit" id="submit" name="submit" value="全部运行(危险操作!请先测试)"></li>
</form> </form>
<?php if ($this->deal) : ?>
<div id="mdlist">
已处理数据:
<?php foreach ($this->deal as $deal): ?>
<ul>
<li>UUID<?php echo $deal['uuid']; ?></li>
<li><a href="/data/<?= $deal['uuid']; ?>"><?= $deal['title']; ?></a></li>
</ul>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php if ($this->test) : ?> <?php if ($this->test) : ?>
<div>测试结果:<br /> <div>测试结果:<br />
<?= $this->escape($this->test) ?> <?= $this->escape($this->test) ?>