Reputation: 466
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('UPDATEtest
...', 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
Upvotes: 1
Views: 4057
Reputation: 9876
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
Upvotes: 3
Reputation: 466
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 );
Upvotes: 0
Reputation: 8248
Try like
$data = array('password' => $randomString , 'flag' => 1);
$db->update( "test", $data, 'public_id ='.$PublicId );
Upvotes: 1