¸ßÊÖÇë½ø£ºlinux mysql C api£» Á¬½ÓÊý¾Ý¿âÎÊÌâ
ÔËÐл·¾³£º redhat£º 4
gcc£º 3.4
mysql£º 5.1
#include <stdio.h>
#include "/usr/include/mysql/mysql.h"
MYSQL_RES* res_ptr;
MYSQL_ROW sqlrow;
unsigned int num_rows = 0;
char ch_sql[200];
MYSQL my_conn;
int main(){
mysql_init(&my_conn);
if (!mysql_real_connect(&my_conn, "localhost", "root", "123456","test",0,NULL,CLIENT_FOUND_ROWS)) {
printf( "ERROR: connect database error\n" );
return 0;
}
printf( "Successful!\n\n" );
return 0;
}
±àÒ룺gcc sqltest.c $(mysql_config --cflags) $(mysql_config --libs) -o sqltest
ÔËÐУº./sqltest
´íÎó£ºcan't connect to localmysql server through socket '/tmp/mysql.sock'
Áí£º 1./tmp/mysql.sockȷʵ´æÔÚ£¬¶øÇÒmysqlÔËÐÐÕý³£
2.ͬһÓû§Ï£¬Í¨¹ýÃüÁîÐУºmysql -u root -p123456; ¿ÉÒÔÕý³£½øÈë
3.ÔÚ±¾µØ»úÆ÷UbuntuÏ£¬±àÒëÔËÐÐÕý³££»Î¨Ò»²»Í¬µÄ¾ÍÊÇgcc°æ±¾
¼±£¡Çë¸ßÊÖÖ
Ïà¹ØÎÊ´ð£º
±àÒëÆ÷£ºC-Free4
mysql µ¥¶À°²×°µÄ£¬ÏÖÔÚΪapache+php+mysql¿ÉÒÔʹÓá£
×î½üÔÚÁ·Ï°c£¬c++£»ÏëÓÃc£¬c++Á¬½ÓÏÂÎÒµÄmysql£¬ºÃ¶àµØ·½¶à˵mysql.hÕÒ²»µ½¡£¶øÇÒÎÒmysqlûÓÐËùνµÄincludeÎļþ¼Ð°¡¡£
Íü¸ßÊÖÖ¸µãÒ»¶ ......
Óиöwinform³ÌÐò,ʹÓÃc#+mysql,ÐèÒªÔÚÒ»¸ö´°ÌåÉèÖÃmysql×Ô¶¯É¾³ý¹¦ÄÜ,°üÀ¨×Ô¶¯É¾³ý¶àÉÙÌì֮ǰµÄÊý¾ÝÒÔ¼°ÊÇ·ñ¿ªÆô×Ô¶¯É¾³ý¹¦ÄÜ,ÎÒ³ÌÐòÍ˳öºó,»¹Ôõô¿ØÖÆMysql×Ô¼ºÉ¾³ý°¡?ÊDz»ÊÇÒªÓÃmysqlµÄeventÀ´ÊµÏÖ?c#¿ÉÒÔµ÷ÓÃmysq ......
#include "stdio.h"
int main()
{
char *ch(char *, char *);
char str1[]="I am glad to meet you!";
char str2[]="Welcom to study C!";
&nb ......