List:General Discussion« Previous MessageNext Message »
From:Gleb Paharenko Date:October 15 2005 1:56pm
Subject:Re: Connectivity problem (?), mysql_ping ()
View as plain text  
Hello.

In my opinion it depends on the value of reconnect flag (the part of
MYSQL structure). I've written a simple program which connects to MySQL
server,
waits a bit and executes mysql_ping. While it is waiting, MySQL server
is being restarted. If mysql.reconnect = 1, mysql_ping() returns
success, otherwise we have "Server has gone away". Here is the test program:

#include<stdio.h>
#include<mysql/mysql.h>
int main()
{
        MYSQL mysql;
        char c;

	printf("Begin\n");
        mysql_init(&mysql);
        mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"mysql");
        if (!mysql_real_connect(&mysql,"localhost"

                                                ,"root"

                                                ,""

                                                ,"test"

                                                ,0

                                                ,NULL

                                                ,0))
        {
            fprintf(stderr, "Failed to connect to database: Error: %s\n",
                                  mysql_error(&mysql));
        }
        mysql.reconnect = 0;
        c=getchar();
        if( mysql_ping(&mysql) != 0)
        {
                printf("Error: %s", mysql_error(&mysql));
        }
        else
        {
                printf("Ok!\n");
        }

}



Lefteris Tsintjelis wrote:
> Hi,
> 
> Is mysql_ping () suppose to restore a db connection even after a db
> restart?
> 
> Thnx,
> 
> Lefteris
> 


-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Gleb Paharenko
 / /|_/ / // /\ \/ /_/ / /__   Gleb.Paharenko@stripped
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.NET
       <___/   www.mysql.com



Thread
Connectivity problem (?), mysql_ping ()Lefteris Tsintjelis15 Oct
  • Re: Connectivity problem (?), mysql_ping ()Gleb Paharenko15 Oct
    • Re: Connectivity problem (?), mysql_ping ()Lefteris Tsintjelis15 Oct
    • Re: Connectivity problem (?), mysql_ping ()Lefteris Tsintjelis16 Oct
      • Re: Connectivity problem (?), mysql_ping ()Gleb Paharenko16 Oct
        • Re: Connectivity problem (?), mysql_ping ()Lefteris Tsintjelis16 Oct