insert.c

来自「在Linux操作系统下的C语言进行MySQL进行增删改查」· C语言 代码 · 共 34 行

C
34
字号
#include <stdio.h>#include <stdlib.h>#include "/usr/include/mysql/mysql.h"int main(int argc,char *argv[]){  MYSQL my_connection;  int res;  mysql_init(&my_connection);  if(mysql_real_connect(&my_connection,"localhost","root","123456","peims",0,NULL,CLIENT_FOUND_ROWS))    {      printf("connection success\n");      res=mysql_query(&my_connection,"insert into student values('','langying','beijing','1949-10-01')");      if(!res)	{	  printf("Inserted %lu rows\n",(unsigned long)mysql_affected_rows(&my_connection));	}      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;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?