How to write a function for MYSQL C API?
Since, it is needed to run several mysql queries in a C script, I tried to
write a function to avoid repeat of codes.
First I separated the mysql connection, which should happen only once in
the entire script as
void mysql_func() {
MYSQL *conn;
char *server = "localhost";
char *user = "root";
char *password = "password";
char *database = "database";
conn = mysql_init(NULL);
mysql_real_connect(conn, server,user, password, database, 0, NULL, 0);
};
but still I need to add declerations such as
MYSQL *conn;
MYSQL_RES *result;
MYSQL_ROW row;
MYSQL_FIELD *mysqlFields;
before using
mysql_query(conn, "SELECT col1 FROM table1");
since function has its own isolated scope.
I wonder if there is a standard way for creating a function to make the
mysql usage in C script as simple as common mysql functions in Perl,
Python, PHP, and other high-level languages?
No comments:
Post a Comment