List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:December 7 2002 11:59pm
Subject:Re: closing database (mysql C API)
View as plain text  
At 14:37 -0800 12/7/02, Admin-Stress wrote:
>Hi,
>
>I wrote an application using mysql C API.
>
>If I exit my application without closing database, will it be closed

You don't "close" a database.  What do you mean?  Do you mean close
the connection to the server?  If so, exiting without closing is the
wrong thing to do.  The server will notice eventually that the connection
is no longer active, but when the client closes it explicitly, that
frees up resources on the server more quickly.

>automatically?
>
>void error(int code) {
>   printf("error: %d\n", code);
>   exit(0);
>}
>
>int main() {
>  ...
>  error(-255);
>  ...
>}
>
>How to pass the mysql database connector to a function? is this correct? :

Normally you would pass a MYSQL* (a pointer) to the function, not a MYSQL.
Then you just pass the pointer to mysql_close().

>
>void error(int code, MYSQL db) {
>   mysql_close(&db);
>   printf("error: %d\n", code);
>   exit(0);
>}
>
>Because I am not sure this will be correct ... should not it using pointer?
>
>Thanks.

Thread
closing database (mysql C API)Admin-Stress7 Dec
  • Re: closing database (mysql C API)Paul DuBois8 Dec