mysql connector详解_MySQL Connector 编程

mysql connector详解_MySQL Connector 编程#include#include#include//使用静态对象库//#pragmacomment(lib,”C:\\ProgramFiles\\MySQL\\MySQLConnectorC6.1\\lib\\vs12\\mysqlclient.lib”)//使用动态链接库//确保libmysql.dll在系统路径中可以搜到#pragmacomment(lib,”C:\\Pr…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

#include

#include#include

//使用静态对象库//#pragma comment(lib, “C:\\Program Files\\MySQL\\MySQL Connector C 6.1\\lib\\vs12\\mysqlclient.lib”)//使用动态链接库//确保 libmysql.dll 在系统路径中可以搜到

#pragma comment(lib, “C:\\Program Files\\MySQL\\MySQL Connector C 6.1\\lib\\libmysql.lib”)

voidsimpleUsega()

{

MYSQL*conn;

conn=mysql_init(NULL);if (conn ==NULL) {

printf(“Error %u: %s\n”, mysql_errno(conn), mysql_error(conn));

exit(1);

}if (mysql_real_connect(conn, “localhost”, “user_name”,”user_password”, NULL, 0, NULL, 0) ==NULL) {

printf(“Error %u: %s\n”, mysql_errno(conn), mysql_error(conn));

exit(1);

}if (mysql_query(conn, “create database frist_db”)) {

printf(“Error %u: %s\n”, mysql_errno(conn), mysql_error(conn));

exit(1);

}

mysql_close(conn);

}

int main() {

MYSQL*mysql =NULL;char pwd[1024];char usr[1024];

printf(“Target platform word length : %d \n”, sizeof(void*) );

printf(“Connector version: %s \n”, mysql_get_client_info());//simpleUsage();//return 0;

printf(“Initializing MySQL Connector… \n”);

mysql_library_init(0, NULL, NULL); //在其他work线程产生之前初始化mysql c库, 不要让mysql_init来调用, 否则可能导致线程安全问题

if (!(mysql =mysql_init(NULL))) {

printf(“Field. \n”);gotoend;

}

printf(“OK, Conecting… \n”);

// 配置用户和密码if (0) {

printf(“Please keyin user_name and password \n”

“name:”);

scanf_s(“%s”, usr, 1024);

printf(“pwd :”);

scanf_s(“%s”, pwd, 1024);

}else{

sprintf_s(usr,1024, “default_user_name”);

sprintf_s(pwd,1024, “default_user_password”);

}

// 连接 localhost 上的服务器if (!mysql_real_connect(mysql, “localhost”, usr, pwd, (const char*) 0, 3306, NULL, 0)) {

printf(“Filed, Error %u, %s \n”, mysql_errno(mysql), mysql_error(mysql) );gotoend;

}

printf(“Login succeed. \n”);//销毁密码

sprintf_s(pwd, 1024, “00000000000000”);

// 查询数据库服务器时间

mysql_query(mysql,”SELECT NOW();”);if (!mysql_errno(mysql)) {

MYSQL_RES*result;

MYSQL_ROW row;intnum_fields;inti;

result=mysql_store_result(mysql);

num_fields=mysql_num_fields(result);while ((row =mysql_fetch_row(result)))

{for(i = 0; i < num_fields; i++)

{

printf(“%s”, row[i] ? row[i] : “NULL”);

}

printf(“\n”);

}

mysql_free_result(result);

}

end:

system(“pause”);

mysql_close(mysql);

mysql_library_end();

return 0;

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/159509.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 转:不同的行业和工作的真实情况是怎样的?「建议收藏」

    ————————————————————————————————————–不同的行业和工作的真实情况是怎样的?收入、发展前景和挑战如何?这个问题可能会耽误您很多时间,但是,这个问题实在是憋了许久。每个大学生考虑以后从事行业的方式都不同,这

    2022年4月8日
    34
  • 常见归一化公式_归一化结果怎么算

    常见归一化公式_归一化结果怎么算 1、线性函数转换,表达式如下:y=(x-MinValue)/(MaxValue-MinValue)说明:x、y分别为转换前、后的值,MaxValue、MinValue分别为样本的最大值和最小值。2、对数函数转换,表达式如下:y=log10(x)说明:以10为底的对数函数转换。3、反余切函数转换,表达式如下:y=atan(x)*2/PI4、式(1)将输入值换算为[-1,1]区间的值,在输出

    2022年10月11日
    5
  • python 根据uuid 获取mac地址

    python 根据uuid 获取mac地址importuuidtry:mac=uuid.UUID(int=uuid.getnode()).hex[-12:]mac_address=’:’.join([mac[e:e+2]foreinrange(0,11,2)])except:mac_address=”print(mac_address)

    2022年8月10日
    37
  • mysql 字符串取前缀_mysql截取字符串的函数总结

    mysql 字符串取前缀_mysql截取字符串的函数总结1、从左开始截取字符串left(str,length)说明:left(被截取字段,截取长度)例:selectleft(content,200)asabstractfrommy_content_t2、从右开始截取字符串right(str,length)说明:right(被截取字段,截取长度)例:selectright(content,200)asabstractfrommy_…

    2022年5月3日
    94
  • Java四舍五入保留两位小数

    Java四舍五入保留两位小数文章目录Java四舍五入保留两位小数一、前言环境二、正文BigDecimalDecimalFormatMathcommons-math3String#formatJava四舍五入保留两位小数一、前言环境开发工具:IntelliJIDEAJDK:1.8BigDecimal:https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.htmlDecimalFormat:https://docs.oracle.com/java

    2022年5月21日
    34
  • Gitlab-CICD最简单明了的入门教程

    Gitlab-CICD最简单明了的入门教程CICD是什么?由于目前公司使用的gitlab,大部分项目使用的CICD是gitlab的CICD,少部分用的是jenkins,使用了gitlab-ci一段时间后感觉还不错,因此总结一下介绍gitlab的CICD之前,可以先了解CICD是什么我们的开发模式经历了如下的转变:瀑布模型->敏捷开发→DevOps(Development、Operations的组合词,是一组过程、方法与系统的统称)后来随着DevOps的兴起,出现了持续集成(ContinuousIntegration)、持续交付(Co

    2022年6月3日
    209

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号