MySql과 C 연동

말차·2022년 9월 3일

🌼지식🌼

목록 보기
7/10
post-thumbnail

우선 개념부터 보자면 (주소)

  • MYSQL : structure represents one database connection and is used by most of MariaDB Connector/C's API functions. The MYSQL structure needs to be allocated and initialized by the mysql_init() API function. It will be released by the mysql_close() function.

  • The MYSQL_RES : structure represents a result set which contains data and metadata(데이터를 설명해주는 데이터) information. It will be returned by the mysql_use_result(), mysql_store_result() and mysql_stmt_result_metadata() API functions and needs to be released by mysql_free_result().

  • MYSQL_ROW : represents an array of character pointers, pointing to the columns of the actual data row. Data will be received by the mysql_fetch_row() function. The size of the array is the number of columns for the current row.

라고 되어있다. 그냥 읽고 음...그렇군하고 넘어가면 될 듯하다. 이게 공식적인 정의이니

MYSQL* conn;
MYSQL connection;
MYSQL_RES* result;
MYSQL_ROW row;

void init()
{
	char 		DB_HOST[] = "localhost";
	char 		DB_USER[] = "root";
	char 		DB_PASS[] = "";
	char 		DB_NAME[] = "bank";

	mysql_init(&connection);
	conn = mysql_real_connect(&connection, DB_HOST, DB_USER, DB_PASS, DB_NAME, 3306, (char *)NULL, 0);
}

"The MYSQL structure needs to be allocated and initialized by the mysql_init() API function."라고 한 것처럼 MYSQL을 처음에 초기화를 시켜준다.

"mysql_real_connect() attempts to establish a connection to a MySQL server running on host. Client programs must successfully connect to a server before executing any other API functions that require a valid MYSQL connection handler structure." = 초기화를 해준 다음 사용자를 호스트로서 mysql에 연결시켜준다. (실제 현업에서는 이러면 안되지 않나..🤔 궁금한 부분이다)

아무튼 여기까지 하면 c와 mysql 연동은 끝이다. 각각의 매개변수에 대해서는 해당 페이지를 참조하면 될 듯하다. 난 뭐지 싶어서 일단 무시했당

0개의 댓글