简体   繁体   中英

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

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 = ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM