mysql:9160
From: k <k <keino048744@xxxxxxxxxx>>
Date: Fri, 09 Apr 2004 10:09:05 +0900
Subject: [mysql 09160] CからMySQLへの接続
ひとつ教えてください。
PHPなど,他の言語からMySQLへ接続し,操作することはできるのですが,
C言語から接続する方法がわかりません(コンパイルができない)。
どなたか教えてください。
Cソースは以下のとおりです。
------------------------------------------------------------
#include <my_global.h>
#include <mysql.h>
static char *opt_host_name = NULL; /* Server host (default=localhost)
*/
static char *opt_user_name = NULL; /* username (default=login name)
*/
static char *opt_password = NULL; /* password (default=none)
*/
static unsigned int opt_port_num = 0; /* port number (use built-in
value) */
static char *opt_socket_name = NULL; /* socket name (use
built-in value) */
static char *opt_db_name = NULL; /* database name
(default=none) */
static unsigned int opt_flags = 0; /* connection
flags (none) */
static MYSQ *conn; /* pointer to connection handler */
int
main(int argc, char *argv[])
{
/* Initialize connection handler */
conn = mysql_init(NULL);
/* Conneect to Server */
mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
opt_db_name, opt_port_num, opt_socket_name, opt_flags);
/* Disconnect from server */
mysql_close(conn);
exit(0);
}
---------------------------------------------------------
コンパイルは
gcc -c -I/usr/include/mysql file.c
gcc -o file file.o -L/usr/lib/mysql -lmysqlclient
--
keisuke
mailto:keino048744@xxxxxxxxxx
__________________________________________________
Do You Yahoo!?
http://bb.yahoo.co.jp/
9159 2004-04-08 19:46 [Shigeru Matsumoto <m] MySQL CC の OpenTable で 1000 件以上見るには? -> 9160 2004-04-09 10:09 ┣[k <keino048744@xxxxx] CからMySQLへの接続 9161 2004-04-09 17:07 ┣[k <keino048744@xxxxx] Re: CからMySQLへの接続 9163 2004-04-09 14:32 ┗[k <keino048744@xxxxx] CからMySQLへの接続