【问题标题】:update zend db with multiple where用多个 where 更新 zend db
【发布时间】:2012-01-08 17:23:13
【问题描述】:

当我执行出现致命错误时,我的查询有问题吗?

$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]:找不到列:C:\xampp\php\PEAR\Zend\Db\Statement 中的 'where 子句'中的 1054 未知列 '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->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 'where 中的未知列 'wdefabcghbcla45'分类在第 234 行的 C:\xampp\php\PEAR\Zend\Db\Statement\Pdo.php 中的 C:\xampp\php\PEAR\Zend\Db\Statement\ 中使用''

【问题讨论】:

  • 您可以尝试显示您的阵列吗?例如,$PublicId、$randomString 的值不清楚?你在哪里得到错误?
  • 我从查询中获取 $publicId,从生成 5 位随机字符串的函数中获取 $randomString
  • 遇到错误时它们的值是什么,这些字段是什么类型?
  • 你得到什么错误信息?
  • 看起来您尝试在表中不存在的地方使用 genhjllafkvy6u5 列。哪一行导致错误?

标签: php zend-db


【解决方案1】:

试试看

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

【讨论】:

    【解决方案2】:

    当我这样尝试时,它奏效了。谢谢你帮助我。

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

    【讨论】:

      【解决方案3】:

      问题是您的 WHERE 子句以 WHERE public_id = wdefabcghbcla45 结尾,因此 MySQL 尝试将“wdefabcghbcla45”作为 column 而不是 value。你需要用引号括起来(单引号或双引号……没关系)。

      试试这样:

      $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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-06
        • 1970-01-01
        相关资源
        最近更新 更多