nizx
nizx

Reputation: 690

PHP Mysql not Deleting rows

Trying to be able to delete some rows from my database but no errors are returned from the statement and if I run the query in phpmyadmin it actually deletes the record. Also executing SELECT statements work with no issues.

The $oId param has an int value

$stmt =  $this->db->prepare('DELETE FROM tbl_bdays WHERE uniqueId = ?');
$stmt->bind_param("i", $oId);
$stmt->execute();
$stmt->close();

Upvotes: 1

Views: 79

Answers (2)

Styphon
Styphon

Reputation: 10447

You have no error checking, you should be checking each step of the way for errors. Try this:

$stmt = $this->db->prepare('DELETE FROM tbl_bdays WHERE uniqueId = ?');
if ( ! $stmt) die('Error whilst preparing: '.$this->db->error);
if ( ! $stmt->bind_param("i", $oId)) die('Error whilst binding: '.$this->db->error);
if ( ! $stmt->execute()) die('Error whilst executing: '.$this->db->error);
$stmt->close();

Upvotes: 0

Kevin
Kevin

Reputation: 41885

If you table name is literally table, then its an error because table is a reserved word

If you really can't change the name then you'll need to wrap it with backticks:

DELETE FROM `table` WHERE uniqueId = ?

Upvotes: 5

Related Questions