mysqltest.cpp

来自「mysql的client测试代码」· C++ 代码 · 共 42 行

CPP
42
字号
// MysqlTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <winsock.h>				/* For windows */
#include "mysql.h"

#pragma comment (lib,"libmysql.lib")


int main(int argc, char* argv[])
{
	MYSQL my_connection;
	int res;
	mysql_init(&my_connection); 
    if (mysql_real_connect(&my_connection, "localhost", "root", "lionheart", "world", 0, NULL, 0)) 
	{
		printf("Connection success\n");
		res = mysql_query(&my_connection, "INSERT INTO country(Name) VALUES('jerry's test code')");
		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 + -
显示快捷键?