服务器每天零点更新数据库

#include <stdio.h>
#include <time.h>
#include <sys/time.h> 
#include <stdlib.h>
#include <signal.h>
#include <mysql.h>
#include <string>
using namespace std;

static int count = 0;
static struct itimerval oldtv;
static int state = 0;
MYSQL *conn_ptr;
int res;
void set_timer()
{
     struct itimerval itv;
     itv.it_interval.tv_sec = 60;
     itv.it_interval.tv_usec = 0;
     itv.it_value.tv_sec = 60;
     itv.it_value.tv_usec = 0;	
     setitimer(ITIMER_REAL, &itv, &oldtv);
}

void signal_handler(int m)
{
     time_t rawtime;
     struct tm * timeinfo;
     time(&rawtime);
     timeinfo = localtime(&rawtime);
     if (timeinfo->tm_hour == 0&&state==0)	{
         if (conn_ptr) {
            res = mysql_query(conn_ptr, "UPDATE miduser SET sate = 0 WHERE sate = 1");
            if (!res) {
                //输出受影响的行数
                printf("Inserted %lu rows\n", (unsigned long)mysql_affected_rows(conn_ptr));
            }	else {
                //打印出错误代码及详细信息
                fprintf(stderr, "Insert error %d: %sn", mysql_errno(conn_ptr), mysql_error(conn_ptr));
            }
        }	else {
          printf("Connection failed\n");	
        }
          state += 1;
    }
    if (timeinfo->tm_hour == 1)state = 0;

int main()
{
     conn_ptr = mysql_init(NULL);
     if (!conn_ptr) 
     {
            printf("mysql_init failed\n");
            return EXIT_FAILURE;	
     }	
    conn_ptr = mysql_real_connect(conn_ptr, "115.28.xx.xx", "xxxx", "xxxx", "fuzhu", 3306, NULL, 0);
    signal(SIGALRM, signal_handler);
    set_timer();
    getchar();
    mysql_close(conn_ptr);	
    return 1;
 }