用多个where更新zend db

时间:2011-11-29 10:57:41

标签: php zend-db

当我执行致命错误时,我的查询出了问题。

$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']; 
}

错误是:

  

致命错误:未捕获异常'PDOException',消息'SQLSTATE [42S22]:未找到列:1054 C:\ xampp \ php \ PEAR \ Zend \ Db \ Statement中'where子句'中的未知列'wdefabcghbcla45' \ Pdo.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->执行(数组)#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未知列'wdefabcghbcla45'在'whe第234行的C:\ xampp \ php \ PEAR \ Zend \ Db \ Statement \中的re子句'':C:\ xampp \ php \ PEAR \ Zend \ Db \ Statement \ Pdo.php

3 个答案:

答案 0 :(得分:3)

问题是你的WHERE子句最后像WHERE public_id = wdefabcghbcla45,因此MySQL试图将“wdefabcghbcla45”作为而不是。你需要用引号括起来(单个或双...不重要)。

试试这样:

$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

答案 1 :(得分:1)

尝试

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

答案 2 :(得分:0)

当我尝试这样的时候,它起作用了。谢谢你的帮助。

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