在我知道所有涉及此例外的多个问题之前,我已经看过他们,但没有找到我的特定问题的答案。大多数问题使用Zend_Db_Table::getDefaultAdapter();
,我没有使用它。相反,我正在使用Application_Model_DbTable_Name
,并且想知道是否可以这样做。Zend_Framework 1.12 SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法中有错误
此外,我确实可以访问,因为那是我查看错误时检查的第一件事。数据库是本地的,我通过MySqlWorkBench以相同的用户/密码访问它。
我的目标是删除行当两列满足控制器动作设定的标准,就像这样:
public function deleteAction(){
$request = $this->getRequest();
$this->_validateDigit($request->getParam('id'));
// _validateDigit(..) checks that the variable is numeric and if it´s not it redirects to
// an error page
$db = new Application_Model_DbTable_BecasPerfiles();
$select = $db->select();
$select->where('unidad=?', $this->_getUnit())
->where('id=?', (int) $request->getParam('id'));
$db->delete($select->getPart(Zend_Db_Select::WHERE));
$this->_redirect('/profile/view-profiles/unit/'.$this->_getUnit());
}
private function _getUnit()
{
return Zend_Registry::getInstance()['session']->unit;
//unit is nothing but a string
}
这里是我的DBTABLE类(真正简单):
class Application_Model_DbTable_BecasPerfiles extends Zend_Db_Table_Abstract
{
protected $_name = 'becas_perfiles';
}
这里是吐出来的是错误:
Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near 'AND (id=7))' at line 1
这是什么叫我的注意力AND(id = 7)),看到额外的括号?那来自哪里?
这里是var_dump($select->getPart(Zend_Db_Select::WHERE));
array(2) { [0]=> string(33) "(unidad='Galería de Arte ULPGC')" [1]=> string(10) "AND (id=7)" }
只是为了乐趣的结果,我想切换where子句的顺序:
$select->where('id=?', (int) $request->getParam('id'))
->where('unidad=?', $this->_getUnit());
这里是输出:
Message: SQLSTATE[42000]: ...
syntax to use near 'AND (unidad='Galería de Arte ULPGC'))' at line 1
还有,AND(unidad ='Galeríade Arte ULP GC'))第二个括号。我真的不知道这是否是问题(但我认为这是因为否则我不知道什么可能是错的)。
我尝试过只使用一个条件(如id),并删除就好了。我非常感谢你的帮助,谢谢!