mysql - 使用 c 删除对 mysql 的查询

标签 mysql c

谁能告诉我从 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 了如指掌,并且 tb1idt1 都不是根据任何形状或形式的用户输入构建的)。

关于mysql - 使用 c 删除对 mysql 的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13643836/

相关文章:

mysql - 如何在 SQL 中显示计数值而不是在同一个表中列出许多行?

MySQL生成年龄金字塔

c++ - 如何在 C/C++ 中将 int 添加到 char[]

mysql - 获取收件人的线程消息

php - 以自定义顺序对 php 数组进行排序

c - c 和 java 中的输出 AES/ECB/PKCS7 不相同

c++ - 为什么是 0022FF08 + sizeof(int) = 0022FF0C 而不是 0022FF0A?

带 pipe 和 fork 的 C 作业

mysql - SQL 将一个表数据连接到其他表

java - JNI下C程序编译报错