Hi again, This is intresting, the documentation indeed mentions that mysql_ping indicates "Zero if the connection to the server is alive" and not that "zero if the server is alive", as I *naturally expected* also, so it is kind of tricky this one. I would expect the same behavior with Unix sockets or TCP sockets though. By restarting the server the connection breaks so I guess the first ping restores that broken connection and therefor returns with a non zero value since the connection was not alive at that moment.
However, since reconnect was set, I would *_very_ naturally expect* to try and reconnect first and then return with a 0 value if everything is OK. This would definetly make much more sence and make mysql_ping () much easier to use, instead of now making an extra mysql_ping () again to see if the first one restored the connection or not... (I will also add those comments to your report) Regards, Lefteris Gleb Paharenko wrote:
Hello. I've found that mysql_ping doesn't work properly with TCP connection (in your test case you put the hostname to "127.0.0.1"). My program was working with "localhost" - connection through the Unix socket. You may want to add you comments to my bug report at: http://bugs.mysql.com/bug.php?id=14057 Lefteris Tsintjelis wrote:I did some extensive testing and it looks like that only the first mysql_ping () fails to reconnect or very possibly returns the wrong result. I am currently using v4.1.14. Regards, Lefteris ---------------------------------------------------- Begin MySQL is up and running Restart MySQL and hit enter (reconnect: 1)... Error: Lost connection to MySQL server during query Ping 2 Ok! Ping 3 Ok! ---------------------------------------------------- #include <stdio.h> #include <mysql.h> int main () { int i; char c; MYSQL mysql; fprintf (stdout, "Begin\n"); mysql_init (&mysql); if (!mysql_real_connect (&mysql, "127.0.0.1", "root", "", "test", 0, NULL, 0)) fprintf (stderr, "Failed to connect to database: Error: %s\n", mysql_error (&mysql)); else fprintf (stdout, "MySQL is up and running\n"); mysql.reconnect = 1; fprintf (stdout, "Restart MySQL and hit enter (reconnect: %d)...", mysql.reconnect); c = getchar (); (void) putc ('\n', stdout); for (i = 1; i < 4; i++) if (mysql_ping (&mysql)) fprintf (stderr, "Error: %s\n", mysql_error(&mysql)); else fprintf (stdout, "Ping %d Ok!\n", i); return (0); }
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
