How to connect mySQL database using C++

前端 未结 4 1107
执笔经年
执笔经年 2020-11-30 21:55

I\'m trying to connect the database from my website and display some rows using C++. So bascily I\'m trying to make an application that does a select query from a table from

4条回答
  •  时光说笑
    2020-11-30 22:27

    Finally I could successfully compile a program with C++ connector in Ubuntu 12.04 I have installed the connector using this command

    'apt-get install libmysqlcppconn-dev'
    

    Initially I faced the same problem with "undefined reference to `get_driver_instance' " to solve this I declare my driver instance variable of MySQL_Driver type. For ready reference this type is defined in mysql_driver.h file. Here is the code snippet I used in my program.

    sql::mysql::MySQL_Driver *driver;
    try {     
        driver = sql::mysql::get_driver_instance();
    }
    

    and I compiled the program with -l mysqlcppconn linker option

    and don't forget to include this header

    #include "mysql_driver.h" 
    

提交回复
热议问题