Passing C++ variables to MySQL query

Hi, does anybody know how to pass C++ variables to MySQL query.

For example:

int y=6;
mysql_query(connection,"update table set column = y");

The update will fail since "y" is not recognized as a C++ variable
how should I modify the above statement so that "y" could be interpreted as "6"?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this:
int y=6;

char temp[32]="";

string str= "update table set column = ";
mysql_query(connection, (char*)str.c_str());

qwe123qwe123Author Commented:
The following are the errors during compilation:

error C2660: 'atoi' : function does not take 3 parameters
error C2065: 'string' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'str'
error C2065: 'str' : undeclared identifier
error C2440: '=' : cannot convert from 'char [38]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2440: '=' : cannot convert from 'char *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2228: left of '.c_str' must have class/struct/union type

7 error(s), 0 warning(s)

Any Hints?
sorry it it not atoi..

It is: itoa

Also you did not include <string.h>, that's why you got compile errors.

The below would work -

int y=6;

char temp[1024]="";

char str[1024]="";
strcpy(str,"update table set column = ");

mysql_query(connection, (char*)str);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qwe123qwe123Author Commented:
It works fine
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.