谁能告诉我从 mysql 数据库表中删除值的正确查询,在我的例子中,表名和 id 是从用户那里接受的,并且该行是根据 id 删除的。这是我的查询
sprintf(Query,"DELETE FROM ('%s') where id = (%d)",tb1,idt1) ;
/*table name is in form of string and id is int */
mysql_query(conn,Query);
最佳答案
您应该删除表名周围的括号:
sprintf(Query,"DELETE FROM '%s' where id = (%d)",tb1,idt1) ;
MySQL 认为这样的查询有语法错误:
delete from (mytable) where id=2;
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 '(mytable) where id=2' at line 1
(我假设您对 SQL injection attacks 了如指掌,并且 tb1
和 idt1
都不是根据任何形状或形式的用户输入构建的)。
关于mysql - 使用 c 删除对 mysql 的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13643836/