MySQL에서 select했는 결과를 배열이나 구조체에 넣고 싶습니다.

신호철의 이미지

MySQL에서여,, Select 했는결과를 변수나 배열이나 구조체에 넣어서, 다른 구

조체들과 비교를 할려고 합니다...

어떻게 하면 넣을수 있을까요??

고수님들,, 가르쳐 주세요~~~~~~ ㅠ.ㅠ

초코리의 이미지

허접하지만 올려 글써보네요..

예전에 MYSQL C API로 한건데 참고 하세요..

MYSQL_ROW에서 그냥 하나씩 뽑아서 복사했거든요..

정말 허접한 코드입니다.

//일자 : 2002년 11월 19일
//제작자 : 이광섭
// 설명 : 
// 	MYSQL과 학생으ㅣ 학번을 받아서 학생정보를 가진 구조체인
// 	STUDENT에 삽입한다.
// 	성공시 1을 실패시 0을 리턴한다
//
// 	학번의 학생 한명만 정보를 리턴하므로
// 	학번에 대한 쿼리를 여러번 해주어야 한다.
//
// 	STUDENT_INFO 구조체중
// 	student_number는 친구 학번
// 	friend_student_number은 친구의 접속 플래그
// 	student_ip는 친구의 IP
// 	student_password 는 Blank
// 	student_new_password는 blank
// 	student_nic는 친구의 닉네임이 들어간다.

/*

typedef struct {
	char student_number[MAX_STUDENT_NUMBER];//8BYTE
	char friend_student_number[MAX_STUDENT_NUMBER];//8Byte
	char student_ip[MAX_IP];//16BYTE
	char student_password[MAX_PASSWORD];//16BYTE
	char student_new_password[MAX_PASSWORD];//16BYTE
	char student_nic[MAX_NIC];//32BYTE
}STUDENT_INFO;//88BYTE

*/


#include "messanger.h"

int query_friend_info(MYSQL * mysql,char * student_number,STUDENT_INFO *student_struct){
	char sql_query[MAX_ARRAY_SIZE];
	int res_num;
	MYSQL_RES *result_friend_info;
	MYSQL_ROW result_friend_info_row;


	strcpy(sql_query,"select student_flag,student_ip,student_nic from use_student where student_number = '");
	strcat(sql_query,student_number);
	strcat(sql_query,"'");
	res_num = mysql_query(mysql,sql_query);


#if DEBUG1
	fprintf(stdout,"sql_query");
#endif

	if(res_num){
		return 0;
	}
	else {
		result_friend_info = mysql_store_result(mysql);//모든 결과를 저장
		result_friend_info_row = mysql_fetch_row(result_friend_info);//결과를 로우파일에 삽입 이곳에서 학번은 유일하므로 로우의 갯수는 1이 된다.)

	//로우에서 나온정보를 스트럭 값에 복사한다.	
		strcpy(student_struct->friend_student_number, result_friend_info_row[0]);
		strcpy(student_struct->student_number,student_number);

		strcpy(student_struct->student_ip , result_friend_info_row[1]);
		strcpy(student_struct->student_nic , result_friend_info_row[2]);
		mysql_free_result(result_friend_info);
		return 1;
	}
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.