mysql_init(&m_mysql);
  if(mysql_real_connect(&m_mysql, "localhost", "mysql", NULL, "user", 0, NULL, 0)) {
sprintf(sql, "select * from usr where phone_num1 = '%s'", telephone);
if(mysql_query(&m_mysql, sql) != 0) {
  return;
    }
else {
  res_ptr = mysql_store_result(&m_mysql);
    if(res_ptr)
     sqlrow = mysql_fetch_row(res_ptr);
}
}

解决方案 »

  1.   

    mysql_init(&m_mysql);
    if(mysql_real_connect(&m_mysql, "localhost", "mysql", NULL, "user", 0, NULL, 0)) {
    sprintf(sql, "select * from usr where phone_num1 = '%s'", telephone);
    if(mysql_query(&m_mysql, sql) != 0) {
      return;
        }
    else {
      res_ptr = mysql_store_result(&m_mysql);
        if(res_ptr)
         sqlrow = mysql_fetch_row(res_ptr);
    }
    }else{
        fprintf(stderr, "Failed to connect to database: Error: %s\n",
              mysql_error(&m_mysql));
    }
    Errors: 
    CR_CONN_HOST_ERROR 
    Failed to connect to the MySQL server. 
    CR_CONNECTION_ERROR 
    Failed to connect to the local MySQL server. 
    CR_IPSOCK_ERROR 
    Failed to create an IP socket. 
    CR_OUT_OF_MEMORY 
    Out of memory. 
    CR_SOCKET_CREATE_ERROR 
    Failed to create a Unix socket. 
    CR_UNKNOWN_HOST 
    Failed to find the IP address for the hostname. 
    CR_VERSION_ERROR 
    A protocol mismatch resulted from attempting to connect to a server with a client library that uses a different protocol version. This can happen if you use a very old client library to connect to a new server that wasn't started with the --old-protocol option. 
    CR_NAMEDPIPEOPEN_ERROR 
    Failed to create a named pipe on Windows. 
    CR_NAMEDPIPEWAIT_ERROR 
    Failed to wait for a named pipe on Windows. 
    CR_NAMEDPIPESETSTATE_ERROR 
    Failed to get a pipe handler on Windows. 
    CR_SERVER_LOST 
    If connect_timeout > 0 and it took longer then connect_timeout seconds to connect to the server or if the server died while executing the init-command.
      

  2.   

    mysql_init(&m_mysql);
    if(mysql_real_connect(&m_mysql, "localhost", "mysql", NULL, "user", 0, NULL, 0)) {
    sprintf(sql, "select * from usr where phone_num1 = '%s'", telephone);
    if(mysql_query(&m_mysql, sql) != 0) {
      return;
        }
    else {
      res_ptr = mysql_store_result(&m_mysql);
        if(res_ptr)
         sqlrow = mysql_fetch_row(res_ptr);
    }
    }else{
        fprintf(stderr, "Failed to connect to database: Error: %s\n",
              mysql_error(&m_mysql));
    }