tags:

views:

56

answers:

2

Here is my code

int main(int argc,char *argv[])
  {
 mysql_init(&mysql); 

 connection = mysql_real_connect(&mysql,.............,"3306",0);

 if (connection == NULL)

 {
 cout << mysql_error(&mysql);

 return 1;

 }
 else
 {
 int id=1;

 mysqlpp::Query query=connection.query("select * from pipe");

 //query3<<"select pipe_id from pipe where version_id='"<<id<<"'";

 if (mysqlpp::StoreQueryResult ares=query.store());

 for(size_t i=0;i<ares.num_rows();i++)

 38 cout<<ares[i]["version_id"]<<ares[i]["pipe_id"]<<std::endl;

 // mysql_query(&mysql,query3.str().c_str());



}

 mysql_close(connection);

return 0;


};

I am getting this error

In function ‘int main(int, char**)’:

error: request for member ‘query’ in ‘connection’, which is of non-class type ‘MYSQL*’

A: 

remove ; after if here:

if (mysqlpp::StoreQueryResult ares=query.store()); <----

I would recommend to use brackets around if body, just for readability and other surprises. You could also check the compiler warnings. I am sure that the compiler will warn you about this statement.

Move the declaration and initialization of ares variable outside if statement, too.

Later edit: connection is a pointer. So use indirection, meaning -> instead of .

Cătălin Pitiș
sorry I have done that can you let me know whats going wrong error: request for member ‘query’ in ‘connection’, which is of non-class type ‘MYSQL*’
Judy
A: 

You are mixing calls to the C API and the C++ API, this approach won't work.

I suggest you look at the MySQL++ turorial, and e.g. the example at http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html

In particular, replace this:

mysql_init(&mysql); 
 connection = mysql_real_connect(&mysql,.............,"3306",0);
 if (connection == NULL)
 {
 cout << mysql_error(&mysql);

 return 1;

 }
 else
 {

with

mysqlpp::Connection conn(false);
if (!conn.connect("mydb", "localhost", "myuser", "mypassword")) {
    cout << "DB connection failed: " << conn.error() << endl;
    return 1;
} else {
nos
Hi I know but i am already able to insert and update the values in the database with this approach
Judy
@sandeep Maybe you're doing that using the C api. Either works, you just have to decide which you want to use.
nos