Skriniar Gregor writes:
> Dear all,
>
> I experienced some problems with using MySQL API:
> My problem is that if I don't use database a long time it is disconnected and when I
>try to connect again at first I use method mysql_ping(), which reopens connection and
>that's the point. Please see next code of MySQL API:
>
> static my_bool mysql_reconnect(MYSQL *mysql)
> {
> MYSQL tmp_mysql;
>//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>local variable
> DBUG_ENTER("mysql_reconnect");
>
> if (!mysql->reconnect ||
> (mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info)
> {
> /* Allov reconnect next time */
> mysql->server_status&= ~SERVER_STATUS_IN_TRANS;
> DBUG_RETURN(1);
> }
> mysql_init(&tmp_mysql);
> tmp_mysql.options=mysql->options;
> bzero((char*) &mysql->options,sizeof(mysql->options));
> if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
> mysql->db, mysql->port, mysql->unix_socket,
> mysql->client_flag))
> DBUG_RETURN(1);
> tmp_mysql.free_me=mysql->free_me;
> mysql->free_me=0;
> mysql_close(mysql);
> *mysql=tmp_mysql;
>//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>the in/out param is pointed to local variable. What's a wilderness?!?
> net_clear(&mysql->net);
> mysql->affected_rows= ~(my_ulonglong) 0;
> DBUG_RETURN(0);
> }
>
> This code was downloaded from www.mysql.com (today - 4th Feb 2002).
> Is it really a bug or I just overlooked something? Thanks in advance!
>
> Best regards
> Gregor Skriniar
>
> SIEMENS AG
> ICM N PG U SE D6
> D-13629 Berlin
>
> Phone: +49 30 386 49590
> Fax: +49 30 386 49118
> Email: [EMAIL PROTECTED]
Hi!
First of all, you are not supposed to use functions line net.clear(),
as those might truly break our client - server protocol. Also, you
should not change our internal fields, like free_me, although in the
above case you did not harm, as tmp_mysql should not be freed anyway,
so your code has no effect. This holds for other fields, which should
be accessed only through our C API functions, and not meddled with
directly.
When connection is idle for wait_timeout seconds, it will be closed,
so I do not see what is your problem.
I also do not see why should you use mysql_ping to reconnect.
--
Regards,
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic <[EMAIL PROTECTED]>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Fulltime Developer
/_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus
<___/ www.mysql.com
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php