如何使用预准备语句防止 C 语言中的 SQL 注入?

发布于 2024-12-22 04:09:39 字数 397 浏览 4 评论 0原文

我必须保护我的软件免遭 SQL 注入。

这是我的 C 代码的示例:

char myquery[QUERY_LEN];
sprintf(myquery, "select * from patient p where p.id_doc='%s'", us_names[index].name);

if (mysql_query(conn, myquery )) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    exit(1);
}

我想使用准备好的语句,因为我读到这是最好的解决方案,但我不明白它是如何工作的。

我使用了 Google,但没有找到任何 C 语言的示例。

你能给我一个用我的代码编写的示例吗?

I have to protect my software from SQL Injection.

Here is an example of my C code:

char myquery[QUERY_LEN];
sprintf(myquery, "select * from patient p where p.id_doc='%s'", us_names[index].name);

if (mysql_query(conn, myquery )) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    exit(1);
}

I want to use prepared statement, because I read that is the best solution, but I don't understand how it works.

I used Google but I didn't find any example in C.

Can you make me an example with my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま昔日黯然 2024-12-29 04:09:39

欢迎来到SO。您找不到您的代码的完整示例。只是一般的例子。如果您想了解有关预防代码注入的更多信息,请搜索该主题,而不是搜索您的具体问题。

一些文章:

Welcome to SO. You won't find complete examples for your code. Just generic examples. If you want to learn more about prevention of code injection, then google for that topic, not for your specific problem.

Some articles:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文