001
06.02.2006, 18:15 Uhr
xXx
Devil
|
du musst die <mysql.h> includieren... vllt hilft dir ne kleine Klasse die ich dazu mal geschrieben hab...
C++: |
class CDevilMySQLClient { public: CDevilMySQLClient(void); ~CDevilMySQLClient(void);
protected: MYSQL *m_pConnection; // pointer the MYSQL structure MYSQL_RES *m_pResult; // pointer to the result set structure MYSQL_ROW m_Row; // row information char* m_pcDB; // Database char* m_pcPW; // Password char* m_pcUser; // Username char* m_pcHost; // Server char m_cQuery[256]; // Queries
// Test! - brauchst de net ;) CListCtrl *m_pListCtrl; // Pointer to the ListCtrl which stores the query information.
public: bool Init(MYSQL* pMySQL = NULL, CDevilSkinListCtrl *pListCtrl = NULL); // Initialize the MYSQL structure bool Connect(const char* cDB, const char* cServer, const char* cPasswort, const char* cAccount); // Connect the MYSQL Strukture with a Server void Close(MYSQL* pMySQL = NULL); // Close the MYSQL structure bool Exit(); // Control that the MYSQL structure is deleted. bool Query(char* pcQuery); // ... };
|
C++: |
CDevilMySQLClient::CDevilMySQLClient(void) { m_pcDB = 0; m_pcHost = 0; m_pcPW = 0; m_pcUser = 0; m_pConnection = NULL; m_pResult = NULL; m_Row = NULL; m_pListCtrl = NULL; }
CDevilMySQLClient::~CDevilMySQLClient(void) { Exit(); }
bool CDevilMySQLClient::Init(MYSQL* pMySQL, CDevilSkinListCtrl *pListCtrl) { if(pMySQL != NULL) m_pConnection = mysql_init(pMySQL); else m_pConnection = mysql_init(NULL);
if(!m_pConnection) return false; if(!pListCtrl) return false; m_pListCtrl = pListCtrl;
return true; }
bool CDevilMySQLClient::Connect(const char* cDB, const char* cServer, const char* cPasswort, const char* cAccount) { if (!mysql_real_connect(m_pConnection, cServer, cAccount, cPasswort, cDB, 0, NULL, 0)) return false;
strcpy(m_pcDB, cDB); strcpy(m_pcHost, cServer); strcpy(m_pcPW, cPasswort); strcpy(m_pcUser, cAccount);
return true; }
bool CDevilMySQLClient::Query(char* pcQuery) { if(!mysql_query(m_pConnection, pcQuery)) //query the database return false;
m_pResult = mysql_store_result(m_pConnection);
char szMessage[128]; sprintf(szMessage, "Number of entries in the database: %d", mysql_num_rows(m_pResult)); // Das ist nur zum Test... also ich guck noch wie viele Items mir mit dem Query zurück geliefert wurden ;) m_pListCtrl->InsertItem(m_pListCtrl->GetItemCount()+1, szMessage);
mysql_free_result(m_pResult); return true; }
void CDevilMySQLClient::Close(MYSQL* pMySQL) { if(pMySQL) mysql_close(pMySQL); else mysql_close(m_pConnection); }
bool CDevilMySQLClient::Exit() { if(m_pConnection) m_pConnection = NULL;
if(m_pConnection != NULL) return false;
if(m_pResult) m_pResult = NULL;
if(m_pListCtrl) m_pListCtrl = NULL;
return true; }
|
|