zoukankan      html  css  js  c++  java
  • Linux编程 使用C在mysql中插入数据

    1. 代码编写

    #include <stdlib.h>
    #include <stdio.h>
    #include "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""mysql""mysql"0, NULL, 0)) 
        {
            printf("Connection success\n");
            res = mysql_query(&my_connection, "INSERT INTO children(fname, age) VALUES('david', 8)");
            
            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;
    }

    2. 插入前

    3. 运行结果

    技术改变世界
  • 相关阅读:
    java中的注解
    jQuery中的pushStack
    jenkins+maven+svn构建项目,及远程部署war包到tomcat上
    mysql中的find_in_set的使用
    svn的使用总结
    poi导出excel,以字符串格式输出数字
    eclipse中在整个工程中查找一个字符串的步骤
    Android Service学习
    Android生成签名文件
    开源移动医疗应用框架:mHealhDroid及APP
  • 原文地址:https://www.cnblogs.com/davidgu/p/2518190.html
Copyright © 2011-2022 走看看