hi,

I have trouble with getting info from my table, this is my code:

#include "stdafx.h"
#include <iostream>
#include <mysql++.h>
#include <manip.h> 
using namespace std;

#define HOST ""
#define USER "senergy"
#define PASSWORD ""
#define DATABASE ""
#define PORT 3306

// deleted info :)

int main(int argc, char *argv[])
{
	try
	{
		mysqlpp::Connection connection(DATABASE, HOST, USER, PASSWORD, PORT);
		mysqlpp::Query query = connection.query("SELECT * FROM accounts");
		mysqlpp::StoreQueryResult result = query.store();
		cout << result[0]["login"];
	}
	catch(mysqlpp::Exception e){
		cerr << "problem: " << e.what() << endl;
		return -1;
	}
	cin.get();
	return 0;
}

well, after executing, I'll get this error:

http://filebeam.com/e5275cc9d8a9738d7f6e672692cca1ae.jpg

and if I use

"SELECT login FROM accounts"

and

cout << result[0]

I'll get 1 as output, not my login username, without any error

with this:

cout << "Number of records: " << result.size() << '\n';
		for(size_t i = 0; i < result.size(); ++i)
			cout << result[i]["id"] << '\n';

I'm getting 0 records, so there is something wrong with it, i'm using same mysql details as I'm using in createaccount and it's working well, I've used

"SELECT acct FROM accounts WHERE login = 'senergy'"

too but it's causing another debug error (this works in navicat console well)

Have you seen this example program? Put an if statement around line 21 to insure the query succeeded.

ok so now I have

int main(int argc, char *argv[])
{
	try
	{
		mysqlpp::Connection connection(DATABASE, HOST, USER, PASSWORD, PORT);
		mysqlpp::Query query = connection.query("SELECT acct FROM accounts WHERE login = 'senergy'");
		if(mysqlpp::StoreQueryResult result = query.store())
		{
			cout << "We have:" << endl;
			for(size_t i = 0; i < result.num_rows(); i++)
			{
				cout << "\t" << result[i][0] << endl;
			}
		}
		else
		{
			cerr << "Failed to get item list: " << query.error() << endl;
			return 1;
		}
	}
	catch(mysqlpp::Exception e){
		cerr << "problem: " << e.what() << endl;
		cin.get();
		cin.get();
		return -1;
	}
	cin.get();
	cin.get();
	return 0;
}

and I'm still getting that debug error, now after printing "we have" sentence

nvm, I got it..

Please mark this thread Solved.

I have trouble with my code. Please help me :(( Visual c++ 2010.

#include <iostream>
#include <mysql++.h>
#include <iomanip>

int main(void)
{

    mysqlpp::Connection con=false;
    con.connect("test", "localhost", "root", "hesoyam");

    if(con)
    {
        std::cout<<"Conectare reusita\n\n";

        mysqlpp::Query sql1=con.query("select * from `useri`");
        mysqlpp::StoreQueryResult res;
        sql1.parse();
        if(res=sql1.store())
        {

        try{


            size_t i;
            for(i=0;i<res.num_rows();i++)
            {
                std::cout<<res[i]["nume"]<<std::endl;
            }

        }
        catch(mysqlpp::Exception e)
        {
            std::cout<<e.what();
        }
    }else{
        std::cout<<"Eroare interogare";
    }
    }else{
        std::cout<<"Eroare conectare\n\n";
    }

    std::cin.get();

    return 0;
}

I get this error: http://filebeam.com/ffa0df6b2dacfbac09b6513dd5a2d830.jpg

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.