1

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\php\PEAR\Zend\Db\Statement\ in C:\xampp\php\PEAR\Zend\Db\Statement\Pdo.php on line 234

9
  • Could you try to diplay your arrays? For example, it's not clear value of $PublicId, $randomString? Where error do you get? Commented Nov 29, 2011 at 11:01
  • i am getting $publicId from query and $randomString from function where i am generating 5 digit random string Commented Nov 29, 2011 at 11:06
  • What are their values when you get an error and what type are these fields? Commented Nov 29, 2011 at 11:12
  • What error message do you get? Commented Nov 29, 2011 at 11:15
  • It looks like you try to use genhjllafkvy6u5 column it where which doesn't exists in table. What line causes an error? Commented Nov 29, 2011 at 11:25

3 Answers 3

3

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. 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

Sign up to request clarification or add additional context in comments.

Comments

1

Try like

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

Comments

0

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 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.