|
|
|
นอกเรื่อง นิดค่ะ ใครพอจะทราบวิธีเขียน C++ ติดต่อฐานข้อมูลบ้าง หรือมีอะไรดีๆ แนะนำ รบกวนด้วยค่ะ |
|
|
|
|
|
|
|
Code (C++)
#include <stdio.h>
#include <mysql.h>
void main()
{
MYSQL *link;
MYSQL_RES *result;
MYSQL_ROW row;
int numofrows;
link = mysql_init(NULL);
mysql_real_connect(link,"localhost","","","game",0,NULL,0);
mysql_query(link,"SELECT * FROM playerinfo");
result = mysql_store_result(link);
numofrows = mysql_num_rows(result);
printf("Num of result = %d\n",numofrows);
while( row = mysql_fetch_row(result) )
{
printf("%s %s %s %s \n",row[0],row[1],row[2],row[3]);
}
mysql_close(link);
}
Credit : http://www.thaidev.com/index.php?cmd=showtitle&id=34
|
|
|
|
|
Date :
2011-03-15 17:11:31 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C++)
#include "stdafx.h"
#include <iostream>
#include <my_global.h>
#include <mysql.h>
using namespace std;
int main(int argc, char **argv)
{
MYSQL *conn;
conn = mysql_init(NULL);
if (conn == NULL) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
}
if (mysql_real_connect(conn, "mysql9.000webhost.com", "user", "password", "database", 0, NULL, 0) == NULL) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
}
if (mysql_query(conn, "INSERT INTO shoutbox (message, author, eml, date, ip) VALUES ('heya','me','[email protected]','07:07 AM 27th May','141.85.0.113')")) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
}
mysql_close(conn);
}
Credit : http://www.daniweb.com/software-development/cpp/threads/286631
|
|
|
|
|
Date :
2011-03-15 17:14:08 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|