Problem with MySQL function in C App
Posted by: Joe Cock
Date: June 27, 2010 06:56AM

Hello!

I'm trying to write a function in my application, which expects a SQL command as the input. Then, the function should fetch the result of the DB, and put it in a string/variable and return that value. I know there are some problems concerning the data types in my function, because when i call the function I get an segmentation fault.

Where are the errors?

-----------------------------
char* mysqlcommand(const char queryvar[100])
{
MYSQL *conn;
MYSQL_RES *result;
MYSQL_ROW row;

char *server = "localhost";
char *user = "root";
char *password = "pwd";
char *database = "dbase";

conn = mysql_init(NULL);

mysql_real_connect(conn, server, user, password, database, 0, NULL, 0);

mysql_query(conn, queryvar);

result = mysql_use_result(conn);

while ((row = mysql_fetch_row(result)) != NULL)
sprintf(binputvar1, "%s", row[0]);

return binputvar1;

mysql_free_result(result);
mysql_close(conn);

}
----------------------------

This is how I call the function:

mysqlcommand("SELECT name FROM testtable WHERE arg = 1");


Please help me with that! Thanks!

Options: ReplyQuote


Subject
Views
Written By
Posted
Problem with MySQL function in C App
879
June 27, 2010 06:56AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.