gpt4 book ai didi

运行 sql DELETE 查询但不在数据库中执行的 php 命令

转载 作者:行者123 更新时间:2023-11-29 00:40:54 25 4
gpt4 key购买 nike

我在 php 中写了这个 MYsql DELETE 函数

function DeleteProduct($thisCatalog) {

$connB = new ProductDAO();
$connB->Connect();
$pro_query = "DELETE * FROM Ikea WHERE `CatalogNumber` = $thisCatalog";
$db_result = $connB->ExecSQL($pro_query);

$html_result = 'Your Product Has Been Deleted! ';

$connB->Disconnect();
return $html_result;
}

这是执行命令

DeleteProduct($CatalogNumber);

最佳答案

删除语法与选择语法不同(您根本不需要选择列名或在其中使用 *):

"DELETE FROM Ikea WHERE `CatalogNumber` = $thisCatalog";

应该可以解决问题。

还有一些来 self 的测试数据库的例子:

mysql> select * from first;
+------+-------+
| id | title |
+------+-------+
| 1 | aaaa |
| 2 | bbbb |
| 3 | cccc |
| 4 | NULL |
| 6 | gggg |
+------+-------+
5 rows in set (0.00 sec)

mysql> insert into first values (7, 'cccc');
Query OK, 1 row affected (0.01 sec)

mysql> select * from first;
+------+-------+
| id | title |
+------+-------+
| 1 | aaaa |
| 2 | bbbb |
| 3 | cccc |
| 4 | NULL |
| 6 | gggg |
| 7 | cccc |
+------+-------+
6 rows in set (0.00 sec)

mysql> delete from first where id=7;
Query OK, 1 row affected (0.01 sec)

mysql> select * from first;
+------+-------+
| id | title |
+------+-------+
| 1 | aaaa |
| 2 | bbbb |
| 3 | cccc |
| 4 | NULL |
| 6 | gggg |
+------+-------+
5 rows in set (0.00 sec)

关于运行 sql DELETE 查询但不在数据库中执行的 php 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12331634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com