简体   繁体   English

用多个where更新zend db

[英]update zend db with multiple where

Is something wrong with my query when i am executing getting fatal error. 当我执行致命错误时,我的查询出了问题。

$select = $db->select()
    ->from('test', '*')
    ->where('user_id = ?', 1)
    ->where('url is NULL');
$Details = $db->fetchAll($select);

foreach ($Details as $row1) {
    $PublicId = $row1['public_id'];
    $data = array('password' => $randomString , 'flag' => 1);

    $db->update("test", $data, 'public_id =' . $PublicId);
    $pass = $row1['password']; 
}

Error is: 错误是:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'wdefabcghbcla45' in 'where clause'' in C:\\xampp\\php\\PEAR\\Zend\\Db\\Statement\\Pdo.php:228 Stack trace: #0 C:\\xampp\\php\\PEAR\\Zend\\Db\\Statement\\Pdo.php(228): PDOStatement->execute(Array) #1 C:\\xampp\\php\\PEAR\\Zend\\Db\\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array) #2 C:\\xampp\\php\\PEAR\\Zend\\Db\\Adapter\\Abstract.php(479): Zend_Db_Statement->execute(Array) #3 C:\\xampp\\php\\PEAR\\Zend\\Db\\Adapter\\Pdo\\Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE test ...', Array) #4 C:\\xampp\\php\\PEAR\\Zend\\Db\\Adapter\\Abstract.php(634): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE test ...', Array) #5 D:\\Zend Workspace\\Test\\testDelete.php(39): Zend_Db_Adapter_Abstract->update('test', Array, 'test_public_id...') #6 {main} Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'wdefabcghbcla45' in 'where clause'' in C:\\xampp 致命错误:未捕获异常'PDOException',消息'SQLSTATE [42S22]:未找到列:1054在C:\\ xampp \\ php \\ PEAR \\ Zend \\ Db \\ Statement \\ Pdo中'where子句'中的未知列'wdefabcghbcla45'。 php:228堆栈跟踪:#0 C:\\ xampp \\ php \\ PEAR \\ Zend \\ Db \\ Statement \\ Pdo.php(228):PDOStatement-> execute(Array)#1 C:\\ xampp \\ php \\ PEAR \\ Zend \\ Db \\ Statement.php(300):Zend_Db_Statement_Pdo - > _ execute(Array)#2 C:\\ xampp \\ php \\ PEAR \\ Zend \\ Db \\ Adapter \\ Abstract.php(479):Zend_Db_Statement-> execute(Array)#3 C :\\ xampp \\ php \\ PEAR \\ Zend \\ Db \\ Adapter \\ Pdo \\ Abstract.php(238):Zend_Db_Adapter_Abstract-> query('UPDATE test ...',Array)#4 C:\\ xampp \\ php \\ PEAR \\ Zend \\ Db \\ Adapter \\ Abstract.php(634):Zend_Db_Adapter_Pdo_Abstract-> query('UPDATE test ...',Array)#5 D:\\ Zend Workspace \\ Test \\ testDelete.php(39):Zend_Db_Adapter_Abstract-> update(' test',Array,'test_public_id ...')#6 {main}下一个异常'Zend_Db_Statement_Exception',消息'SQLSTATE [42S22]:未找到列:1054 C:\\中'where子句''中的未知列'wdefabcghbcla45' XAMPP \\php\\PEAR\\Zend\\Db\\Statement\\ in C:\\xampp\\php\\PEAR\\Zend\\Db\\Statement\\Pdo.php on line 234 第234行的C:\\ xampp \\ php \\ PEAR \\ Zend \\ Db \\ Statement \\ Pdo.php中的\\ php \\ PEAR \\ Zend \\ Db \\ Statement \\

The problem is your WHERE clause was ending up like WHERE public_id = wdefabcghbcla45 therefore MySQL was trying "wdefabcghbcla45" as a column instead of a value . 问题是你的WHERE子句最终像WHERE public_id = wdefabcghbcla45因此MySQL试图将“wdefabcghbcla45”作为而不是 You need to wrap it with quotes (single or double..doesn't matter). 你需要用引号括起来(单个或双...不重要)。

Try it like this: 试试这样:

$where = $db->quoteInto('public_id = ?', $PublicId);
$db->update('test', $data, $where);

http://files.zend.com/help/Zend-Framework/zend.db.html#zend.db.adapter.quoting.quote-into http://files.zend.com/help/Zend-Framework/zend.db.html#zend.db.adapter.quoting.quote-into

Try like 试试吧

$data = array('password' => $randomString , 'flag' => 1);
$db->update( "test", $data, 'public_id ='.$PublicId );

When I tried like this, it worked. 当我这样尝试时,它起作用了。 Thanks for helping me. 谢谢你的帮助。

$data = array('password' => $randomString , 'flag' => 1);
$where = "public_id = '" . $PublicId."'";
$db->update( "test", $data, $where );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM