0

In my Application_Model_DbTable_User, I have the following function:

public function deleteUser($username)
{
    $this->delete('username = ' . (string) $username);
}

This function is being called from my AdminController, with this three lines of code.

$uname = $this->getRequest()->getParam('username');
$user = new Application_Model_DbTable_User();
$user->deleteUser($uname);

This error however, turns up.

Column not found: 1054 Unknown column 'test' in 'where clause'

With test being the user I am trying to delete.

This code is adapted from a previous code which deletes based on id, a INT field, which works perfectly fine. What am I doing wrong? I would be happy to give more detailed codes if needed. Thanks.

ByteNudger
  • 1,545
  • 5
  • 29
  • 37
Ayrx
  • 2,092
  • 5
  • 26
  • 34

1 Answers1

2

Your query isn't quoted:

$this->delete('username = ' . (string) $username);

This equates to:

WHERE username = test

If you use the where() method, it will do this for you:

$table->where('username = ?', $username);

Or (like the example in the docs):

$where = $table->getAdapter()->quoteInto('bug_id = ?', 1235);
$table->delete($where);
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • it's better like that : $db = $this->getAdapter(); $table->where($db->quoteInto('username = ?', $username)); – Mr_DeLeTeD Jul 24 '12 at 13:34