Search code examples
c++mysqlmysql++

MySQL++ returns nothing


I have recently decided to learn MySQL++ and have had some trouble getting started. Anyways, I am trying to make a program that stores most recent versions of programs (to help with Homebrew).

main.cpp:

#include <mysql++/mysql++.h>
#include <stdlib.h>

using namespace std;
using namespace mysqlpp;

int main() {
    Connection conn (false);
    conn.connect ("db.ssqls", "localhost");
    Query query = conn.query();
    query << "SELECT * FROM version;";
    StoreQueryResult ares = query.store();
    for (size_t i = 0; i < ares.num_rows(); i++)
        cout << "Name: " << ares[i]["name"] << " - Address: " << ares[i]["address"] << endl;
    return (EXIT_SUCCESS);
}

I compiled this with g++ -lmysqlpp -g main.cpp -o main -DMYSQLPP_MYSQL_HEADERS_BURIED. I then ran this using ./main.

Running SELECT * FROM version; on db.ssqls using sqlite3 gives 1|cmake|3|11|0|cmake.org|.

I was debugging (with lldb) this when I noticed that ares.num_rows()==0. In fact, it seems as if nothing happened.

What is wrong with my code?


Solution

  • Well, turns out you need to have a MySQL server before running the MySQL commands. You need to have mysqld running on your computer.