database.sarang.net
UserID
Passwd
Database
DBMS
ㆍMySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MySQL Devel 13937 게시물 읽기
 News | Q&A | Columns | Tutorials | Devel | Files | Links
No. 13937
또 다른 간단한 C API 사용예
작성자
정재익(advance)
작성일
2001-12-03 03:01
조회수
7,701

#include <sys/time.h>

#include <stdio.h>

#include <mysql.h>

 

void main(char **args) {

MYSQL_RES *result;

MYSQL_ROW row;

MYSQL *connection, mysql;

int state;

 

/* connect to the mySQL database at athens.imaginary.com */

connection = mysql_connect(&mysql, \localhost\, \dshin\, \dshin\);

/* check for a connection error */

if( connection == NULL ) {

/* print the error message stored in MsqlErrMsg */

printf(mysql_error(&mysql));

exit(-1);

}

/* select which database to use on the server */

state = mysql_select_db(connection, \dshin\);

/* again, -1 means an error */

if( state == -1 ) {

printf(\%s\n\,mysql_error(connection));

/* close up our connection before exiting */

mysql_close(connection);

exit(-1);

}

state = mysql_query(connection, \SELECT * FROM account\);

if( state == -1 ) {

printf(\%s\n\,mysql_error(connection));

exit(-1);

}

 

/* must call mysql_store_result() before we can issue any

* other Query() calls

*/

result = mysql_store_result(connection);

printf(\Rows: %d\n\, mysql_num_rows(result));

/* process each row in the result set */

printf(\Branch_name Account_number Balance\n\);

while( ( row = mysql_fetch_row(result)) != NULL ) {

printf(\%s %s %s\n\, row[0], row[1], row[2]);

}

 

/* free the result set */

mysql_free_result(result);

/* close the connection */

mysql_close(connection);

printf(\Done.\n\);

}

 

================

Makefile

================

CC=gcc

MYSQLDIR=-L/home/dba/mysql/lib

MYSQLINC=-I/home/dba/mysql/include

MYSQLLIB=-lmysqlclient -lnsl

select: select.c

$(CC) $(MYSQLDIR) $(MYSQLINC) -o select select.c $(MYSQLLIB)

[Top]
No.
제목
작성자
작성일
조회
16233[프로그램] DB 이용한 컨텐츠 관리 시스템
문태준
2002-06-12
11349
15744MySQL 에러코드별 에러메세지 입니다.
강병권
2002-04-18
23860
14706Perl with MySQL
정재익
2002-01-11
12852
13809간단한 api 사용예
이노성
2001-11-25
8518
13937┕>또 다른 간단한 C API 사용예
정재익
2001-12-03 03:01:50
7701
13126[예제] mysql c 프로그램(소켓 프로그래밍 포함) [1]
문태준
2001-10-20
12927
13077JDBC 를 이용한 MySQL 응용 프로그램 작성법
정재익
2001-10-18
9740
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.047초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다