我想刪除我的頁表中的條目。一旦刪除它,它將級聯到對象表。不用擔心,如果我通過使用簡單的DELETE
刪除條目,它就可以工作。但是,我需要指定一些條件:內部加入表時執行刪除
PAGES表
+--------------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+--------------+------+-----+---------+----------------+
| page_id | int(11) | NO | PRI | NULL | auto_increment |
| users_id | int(11) | NO | MUL | NULL | |
| page_value | varchar(20) | NO | UNI | NULL | |
+--------------------------+--------------+------+-----+---------+----------------+
OBJECTS表
+----------------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------------+-------------+------+-----+---------+----------------+
| objects_id | int(11) | NO | PRI | NULL | auto_increment |
| page_id | int(11) | NO | MUL | NULL | |
| objects_name | varchar(50) | NO | | NULL | |
| objects_avail | varchar(20) | NO | | NULL | |
+----------------------------+-------------+------+-----+---------+----------------+
如果objects_avail == "ALL"
,我一定不包括級聯刪除的條目。我想出了這個SQL查詢,但得到了一個錯誤:爲PDO的佔位符
["42000",1064,"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS p INNER JOIN objects AS o ON p.page_id = o.page_id WHER' at line 1"]
示例值:
$query = "
DELETE FROM pages AS p
INNER JOIN objects AS o ON p.page_id = o.page_id
WHERE p.page_id = ?
AND p.users_id = ?
AND p.page_value = ?
AND o.objects_avail != ?";
引發的錯誤
$params = array(81,5,"main page","ALL");
,所有的這是有效的,我相信這不是問題所在。
我懷疑或prettry確定我錯過了一些在我的查詢,請提出任何建議?
嘗試使用這個$查詢=「DELETE FROM AS 'P' INNER JOIN對象作爲o在 'P' 或 '頁'。 'PAGE_ID'= 'o'。'page_id'WHERE'p'。'page_id'=?AND'p'。'users_id'=?AND'p'。'page_value'=?AND'o'。'objects_avail'!=?「; –