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()转义插入数据的更多相关文章

  1. Linux 编程中的API函数和系统调用的关系【转】

    转自:http://blog.chinaunix.net/uid-25968088-id-3426027.html 原文地址:Linux 编程中的API函数和系统调用的关系 作者:up哥小号 API: ...

  2. C#调用Windows API函数截图

    界面如下: 下面放了一个PictureBox 首先是声明函数: //这里是调用 Windows API函数来进行截图 //首先导入库文件 [System.Runtime.InteropServices ...

  3. VBS调用Windows API函数

    Demon's Blog 忘记了,喜欢一个人的感觉 Demon's Blog  »  程序设计  »  VBS调用Windows API函数 « 用VBS修改Windows用户密码 在VB中创建和使用 ...

  4. Python调用Windows API函数编写录音机和音乐播放器

    功能描述: 1)使用tkinter设计程序界面: 2)调用Windows API函数实现录音机和音乐播放器. . 参考代码: ​ 运行界面: ​

  5. PHP用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID

    向mysql 插入数据时,很多时候我们想知道刚刚插入数据的id,这对我们很有用.下面这篇文章就详细给大家介绍了利用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID,有需要的朋友 ...

  6. C++多线程中调用python api函数

    错误场景:一直等待全局锁. 解决方法: 一.首先定义一个封装类,主要是保证PyGILState_Ensure, PyGILState_Release配对使用,而且这个类是可以嵌套使用的. #inclu ...

  7. Linux环境下MySQL数据库用SQL语句插入中文显示 “问号或者乱码 ” 问题解决!

    问题: 在普通用户权限下执行 mysql -u root -p进入mysql数据库,中间步骤省略,插入数据:insert into 库名(属性)values('汉字'); 会出现如下提示:  Quer ...

  8. mysql存储过程批量向表插入数据

    业务需要,往某个表中批量插入数据,使用存储过程插入 首先,要建立一张mysql表,表明为phone_number, 三个字段,id 自增,number 就是要插入的表格,is_used 表示十分已经使 ...

  9. 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 ...

随机推荐

  1. compile libvirt

    POSIX-linux 编译安装libvirt依赖包; 1.yum install device-mapper-devel

  2. [原创小知识] 如何优雅的判断 ie 版本

    之前一直不怎么做低版本ie的前端,毕竟ie的大半江山都被chrome 霸占,但大部分情况下,却还是要去兼容下那些老顽固.一切的原因,都是因为当年微软的年轻气盛,喜欢另起炉灶,真是很无语. 通常我们去h ...

  3. UITextView ios7

    UITextView *textView2 = [[UITextView alloc]initWithFrame:CGRectMake(, textView1.frame.size.height + ...

  4. iOS8新特性之基于地理位置的消息通知UILocalNotification

              苹果在WWDC2014上正式公布了全新的iOS8操作系统. 界面上iOS8与iOS7相比变化不大,只是在功能方面进行了完好.                             ...

  5. [Javascript] What is JavaScript Function Currying?

    Currying is a core concept of functional programming and a useful tool for any developer's toolbelt. ...

  6. Eclipse、MyEclipse使用git插件(egit)

    在开发Java.JavaEE等相关程序时,我们会用到Eclipse或者MyEclipse,同时使用到git作为版本控制软件,所以我们需要在这些IDE上集成git插件,而egit正是Eclipse基金会 ...

  7. Linux之make 、makefile的使用方法

    ◊make是什么? make是一个命令工具,是一个解释makefile中指令的命令工具.它可以简化编译过程里面所下达的指令,当执行 make 时,make 会在当前的目录下搜寻 Makefile (o ...

  8. Managing linux Shell Jobs

    Managing Shell Jobs   When moving jobs between the foreground and background, it may be useful to ha ...

  9. linux groupmems命令

    Because users group membership is defined in two different locations, it can be difficult to find ou ...

  10. 修改登录linux之后显示的默认文件夹目录

    命令如下: ll -a vim .bash_profile 最后一行加上cd 需要显示的文件夹