Linux C 调用MYSQL API 函数mysql_escape_string()转义插入数据
Title:Linux C 调用MYSQL API 函数mysql_escape_string()转义插入数据 --2013-10-11 11:57
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mysql.h" int main(int argc, char *argv[])
{
MYSQL my_connection;
int res;
mysql_init(&my_connection);
char UNAMES[50];
char sql_insert[400];
char *p[5];
p[0]="123456";
p[1]="Fuc'a'k";
p[2]="127.0.0.1";
p[3]="2013-09-26 10:10:10";
p[4]="1"; /*mysql_real_connect(&mysql,host,user,passwd,dbname,0,NULL,0) == NULL)*/
if (mysql_real_connect(&my_connection, "127.0.0.1", "root", "FuckFuck","databasename",0,NULL,CLIENT_FOUND_ROWS))
{
printf("Connection success\n");
mysql_escape_string(UNAMES,p[1],strlen(p[1]));
snprintf(sql_insert, sizeof(sql_insert),"insert into `tablename` (`C1`,`C2`,`C3`,`C4`,`C5`) values ('%s','%s','%s','%s','%s');",p[0],UNAMES,p[2],p[3],p[4]);
res = mysql_query(&my_connection,sql_insert); if (!res)
{
printf("Inserted %lu rows\n",(unsigned long)mysql_affected_rows(&my_connection));
printf("%s------\n",sql_insert);
printf("%s------\n",UNAMES);
/*里头的函数返回受表中影响的行数*/
}
else
{
//分别打印出错误代码及详细信息
fprintf(stderr, "Insert error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
mysql_close(&my_connection);
} else
{
fprintf(stderr, "Connection failed \n"); if (mysql_errno(&my_connection))
{
fprintf(stderr, "Connection error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
}
return EXIT_SUCCESS;
}
Linux C 调用MYSQL API 函数mysql_escape_string()转义插入数据的更多相关文章
- Linux 编程中的API函数和系统调用的关系【转】
转自:http://blog.chinaunix.net/uid-25968088-id-3426027.html 原文地址:Linux 编程中的API函数和系统调用的关系 作者:up哥小号 API: ...
- C#调用Windows API函数截图
界面如下: 下面放了一个PictureBox 首先是声明函数: //这里是调用 Windows API函数来进行截图 //首先导入库文件 [System.Runtime.InteropServices ...
- VBS调用Windows API函数
Demon's Blog 忘记了,喜欢一个人的感觉 Demon's Blog » 程序设计 » VBS调用Windows API函数 « 用VBS修改Windows用户密码 在VB中创建和使用 ...
- Python调用Windows API函数编写录音机和音乐播放器
功能描述: 1)使用tkinter设计程序界面: 2)调用Windows API函数实现录音机和音乐播放器. . 参考代码: 运行界面:
- PHP用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID
向mysql 插入数据时,很多时候我们想知道刚刚插入数据的id,这对我们很有用.下面这篇文章就详细给大家介绍了利用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID,有需要的朋友 ...
- C++多线程中调用python api函数
错误场景:一直等待全局锁. 解决方法: 一.首先定义一个封装类,主要是保证PyGILState_Ensure, PyGILState_Release配对使用,而且这个类是可以嵌套使用的. #inclu ...
- Linux环境下MySQL数据库用SQL语句插入中文显示 “问号或者乱码 ” 问题解决!
问题: 在普通用户权限下执行 mysql -u root -p进入mysql数据库,中间步骤省略,插入数据:insert into 库名(属性)values('汉字'); 会出现如下提示: Quer ...
- mysql存储过程批量向表插入数据
业务需要,往某个表中批量插入数据,使用存储过程插入 首先,要建立一张mysql表,表明为phone_number, 三个字段,id 自增,number 就是要插入的表格,is_used 表示十分已经使 ...
- Mysql向新建表中插入数据, Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89' for column 'UserName' at row 1
在本地通过MYSQL创建测试表 CREATE Table User ( UserId int not NULL PRIMARY KEY auto_increment, //主键自增 UserName ...
随机推荐
- banana pro 板子
http://www.lemaker.org/cn/article-23-1.html
- I - Strategic Game - hdu 1054(最小点覆盖)
题意:用最小的点来覆盖全部的边,因为二分图里面最大的匹配就是最小覆盖,所以直接匹配一下即可 ****************************************************** ...
- GDB错误:Cannot find bounds of current function
http://blog.csdn.net/zoomdy/article/details/17249165 mingdu.zheng <at> gmail <dot> com 使 ...
- Sort List (使用归并排序的链表排序)
Sort a linked list in O(n log n) time using constant space complexity. C++代码的实现: #include<iostrea ...
- redis 控制调用频率
redis提供了rate limit demo 如下所示: INCR key Available since 1.0.0. Time complexity: O(1) Increments the n ...
- STL之set && multiset
一.set 在了解关联容器set之前,让我们先来看看下面这个例子,并猜测该例子输出什么: // stl/set1.cpp #include <iostream> #include < ...
- MM32 RTC学习(兼容STM32)
RTC学习 RTC简述 实时时钟是一个独立的定时器. RTC模块拥有一组连续计数的计数器,在相应软件配置下,可提供时钟日历的功能. 修改计数器的值可以重新设置系统当前的时间和日期. RTC模块和时钟配 ...
- Fragment 创建 传递参数 跳转 典例
抽取的控制Fragment的父Activity /** * 抽象一个Activity托管我们的Single Fragment */ public abstract class SingleFrag ...
- ASP.NET-FineUI开发实践-4(二)
在网上找了找,实验了一下window弹出和关闭的动画效果分享一下. 接上次的代码 default.js window_tips.animCollapse= true;//打开动画效果 window_t ...
- @CacheEvict(value = { "" })
org.springframework.cache.annotation.CacheEvict