얘들 아, 문제는 내가 그것을 서버가 연결되지 않았거나 경우에 저에게 할 수있는 프로그램을 걸리는MySQL의 타임 아웃 - C/C++이 코드 문제에 직면하고있어
시간을 의미하는 제한 시간으로 제한 시간입니다. 난 내
로컬 호스트를 사용하는 경우 난 빠른 답변을 얻을,하지만 난 내 로컬 호스트 외부에 연결할 때이 50sc합니다 -이 완료 될 때까지 응답과 프로그램 frezz에
1.5 분. HOw 나는 frezzing을 고칠 수 있습니까? 아니면
내 자신의 타임 아웃은 50sc 이후에도 계속 기다리는 것과 같이 연결이 실패하고 멈춘다 고 말하면 어떨까요?
내가 더 나은 어떤 도움을 주셔서 감사합니다 그것을 이해할 렸기 때문에 도움으로 코드를 사용하시기 바랍니다 내가 얻을
PS : 당신의 주요 관심사 (이하 "정지"의 경우 MAC
#include "mysql.h"
#include <stdio.h>
#include <stdlib.h>
// Other Linker Flags: -lmysqlclient -lm -lz
// just going to input the general details and not the port numbers
struct connection_details
{
char *server;
char *user;
char *password;
char *database;
};
MYSQL* mysql_connection_setup(struct connection_details mysql_details)
{
// first of all create a mysql instance and initialize the variables within
MYSQL *connection = mysql_init(NULL);
// connect to the database with the details attached.
if (!mysql_real_connect(connection,mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0)) {
printf("Conection error : %s\n", mysql_error(connection));
exit(1);
}
return connection;
}
MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query)
{
// send the query to the database
if (mysql_query(connection, sql_query))
{
printf("MySQL query error : %s\n", mysql_error(connection));
exit(1);
}
return mysql_use_result(connection);
}
int main()
{
MYSQL *conn; // the connection
MYSQL_RES *res; // the results
MYSQL_ROW row; // the results row (line by line)
struct connection_details mysqlD;
mysqlD.server = (char*)"Localhost"; // where the mysql database is
mysqlD.user = (char*)"root"; // the root user of mysql
mysqlD.password = (char*)"123456"; // the password of the root user in mysql
mysqlD.database = (char*)"test"; // the databse to pick
// connect to the mysql database
conn = mysql_connection_setup(mysqlD);
// assign the results return to the MYSQL_RES pointer
res = mysql_perform_query(conn, (char*) "SELECT * FROM me");
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) !=NULL)
printf("%s - %s\n", row[0], row[1], row[2]); // <-- Rows
/* clean up the database result set */
mysql_free_result(res);
/* clean up the database link */
mysql_close(conn);
return 0;
}
타임 아웃은 TCP 스택 내에 있습니다. 조정할 때 뭔가를 할 수는 있지만 플랫폼에 알릴 때까지는 할 수 없습니다. – trojanfoe
Mac을 플랫폼으로 사용하는 경우 – user1262876
로컬 호스트 외부에서 코드를 구현할 때 코드의 기본 사항을 변경 하시겠습니까? 'mysqlD.server = (char *) "Localhost"; "는 비 로컬 호스트 서버에서 이해하지 못합니다. 또한 다른 호스트에 구현할 때 연결합니까? 언젠가는 얼어 버린다고했는데 연결 되나요? – TheNavigat