简体   繁体   English

MySQL-删除一行,如何?

[英]MySQL - Delete a row, how?

Can anyone show me a query in MySQL that would delete rows from all available columns. 任何人都可以向我显示MySQL中的查询,该查询将从所有可用列中删除行。

I use this to insert rows: 我用它来插入行:

$sql = "INSERT INTO " . KEYS . "          // KEYS is a constant
 (key, user_id, time, approved)
 VALUES ('" .  $randkey . "', '" . $user_id . "', '" .  $time . "', '0')";

I need the opposite of this now, delete created rows. 我现在需要与此相反,删除创建的行。

delete from <table> where ....

请记住,delete语句始终用于整行。

Using similar syntax sql = "DELETE FROM " . 使用类似的语法sql =“ DELETE FROM”。 KEYS . 按键 " WHERE 1=1"; “ WHERE 1 = 1”;

Replace 1=1 with the conditions for the row you want to delete or it will delete all rows. 将1 = 1替换为要删除的行的条件,否则它将删除所有行。

Also, it's good to get out of the habit of just dropping variables into SQL as soon as possible, because it will open your code up to SQL Injection attacks. 同样,最好不要早日将变量放入SQL中,因为这样做会使您的代码容易受到SQL Injection攻击。 Look into using parameterized queries. 查看使用参数化查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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