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. 运行结果

    技术改变世界
  • 相关阅读:
    springBoot Mybaits分页错误
    验证码的技术实现原理
    《参与感》----产品篇
    参与感三三法则
    MIUI 的参与感
    从 UI 交互角度说语音识别产品
    语音识别开放平台调研以及主要技术
    测试蓝牙回连技术
    测试语音遥控器语音聊天的坑
    测试语音遥控器扫描连接的要点
  • 原文地址:https://www.cnblogs.com/davidgu/p/2518190.html
Copyright © 2011-2022 走看看