lifuguan 2016-03-16 09:52 采纳率: 0%
浏览 1709

MySQL 连接不到libmysqllib

 #define _CRT_SECURE_NO_WARNINGS
#include <windows.h>  
#include <stdio.h>  
#include <stdlib.h>  
#include <string.h>  
#include <mysql.h>   
#include <iostream> 
#pragma comment(lib,"libmysql64.lib")//连接MysQL需要的库  
#pragma comment(lib,"libmysql.lib")//连接MysQL需要的库  
using namespace std;
int main()
{
    const char user[] = "VISUAL_STUDIO1";         //username  
    const char pswd[] = "ligh123456789";    //password  
    const char host[] = "118.192.151.230";    //or"127.0.0.1"  
    const char table[] = "testdb";       //database  
    unsigned int port = 3306;           //server port          
    MYSQL myCont;
    MYSQL_RES *result;
    MYSQL_ROW sql_row;
    MYSQL_FIELD *fd;
    char column[32][32];
    int res;
    mysql_init(&myCont);
    if (mysql_real_connect(&myCont, host, user, pswd, table, port, NULL, 0))
    {
        cout << "connect succeed!" << endl;
        mysql_query(&myCont, "SET NAMES GBK"); //设置编码格式,否则在cmd下无法显示中文  
        res = mysql_query(&myCont, "select * from uc");//查询  
        if (!res)
        {
            result = mysql_store_result(&myCont);//保存查询到的数据到result  
            if (result)
            {
                int i, j;
                cout << "number of result: " << (unsigned long)mysql_num_rows(result) << endl;
                for (i = 0; fd = mysql_fetch_field(result); i++)//获取列名  
                {
                    strcpy(column[i], fd->name);
                }
                j = mysql_num_fields(result);
                for (i = 0; i<j; i++)
                {
                    printf("%s\t", column[i]);
                }
                printf("\n");
                while (sql_row = mysql_fetch_row(result))//获取具体的数据  
                {
                    for (i = 0; i<j; i++)
                    {
                        printf("%s\n", sql_row[i]);
                    }
                    printf("\n");
                }
            }
        }
        else
        {
            cout << "query sql failed!" << endl;
        }
    }
    else
    {
        cout << "connect failed!" << endl;
    }
    if (result != NULL) mysql_free_result(result);//释放结果资源  
    mysql_close(&myCont);//断开连接  

    return 0;
}

为什么运行结果会有这个::::::

错误 1 error LNK1104: 无法打开文件“libmysql64.lib” d:\用户目录\我的文档\Visual Studio 2013\Projects\MySQL\MySQL\LINK

  • 写回答

1条回答

  • oyljerry 2016-03-16 09:58
    关注

    你这个libmysql64 lib库文件的路径有没有在工程属性中配置

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog