Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Povezivanje na MySQL server, POMOC!

[es] :: C/C++ programiranje :: Povezivanje na MySQL server, POMOC!

Strane: 1 2

[ Pregleda: 8459 | Odgovora: 20 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

vlado_036

Član broj: 108868
Poruke: 8
*.ptt.yu.



Profil

icon Povezivanje na MySQL server, POMOC!12.05.2008. u 11:30 - pre 194 meseci
Moze li neko da mi pomogne i objasni kako da se povezem na MySQL server koristeci Visual C++ 9

Koristim Visual studio 2008, MySQL server 5.0.45, Windows XP SP2

Hvala
 
Odgovor na temu

itf
Zagreb

Član broj: 59794
Poruke: 993
161.53.237.*



+9 Profil

icon Re: Povezivanje na MySQL server, POMOC!12.05.2008. u 13:11 - pre 194 meseci
Jesi možda probao preko ODBC-a?
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.ptt.yu.



+395 Profil

icon Re: Povezivanje na MySQL server, POMOC!12.05.2008. u 14:58 - pre 194 meseci
http://www.functionx.com/visualc/databases/sqltable.htm
Primer je doduse za SQL Server al posto se radi o ODBC drajverima sigurno mozes da se nakacis i na MySQL

Viva lollapalooza
 
Odgovor na temu

vlado_036

Član broj: 108868
Poruke: 8
*.ptt.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!12.05.2008. u 15:05 - pre 194 meseci
Primer je OK ali ja bih u aplikaciju koja vec funkcionise hteo da dodam neke dijaloge koji bi prikazivali podatke iz MySQL baze. Problem je sto je aplikacija je bazirana na dialogu i nema ukljucenu podrsku za baze. Probao sam da u projekat ukljucim sve fajlove iz MySQL include direktorijuma i tako da ih koristim ali ne moze, mada bi mi neka slicna tome varijanta najvise odgovarala.

Moze li u ovom slucaju da se koristi ODBC?

Bilo koji nacin koji radi mi odgovara :)
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.ptt.yu.



+395 Profil

icon Re: Povezivanje na MySQL server, POMOC!12.05.2008. u 15:17 - pre 194 meseci
Naravno da mozes da koristis ODBC API za konekciju ka MySQL serveru ...
U ODBC32.dll su funkcije koje ti to omogucavaju ...
al je sam pristup i koriscenje API-ija dosta slozeno (low-level C ) pa ti stoga preporucujem da skines neki od free "ODBC wrapera" klasa koje ti pojednostavljuju rad
Na primer : . http://www.codeguru.com/cpp/da...tabase/odbc/article.php/c4337/

Viva lollapalooza
 
Odgovor na temu

vlado_036

Član broj: 108868
Poruke: 8
*.ptt.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!21.05.2008. u 10:50 - pre 193 meseci
Probao sam nekoliko (vise od 10) ODBC Wrapper-a ali ni jedan nije hteo da se bez greske kompajlira, svaki za sebe prijavljuje druge greske. Svisu pisani za Visual C++ 6 a ja koristim Visual C++ 9, da li je u tome problem?

Uspeo sam preko CDatabase i CRecordset da iscitavam podatke iz MySQL baze.
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.adsl-1.sezampro.yu.



+395 Profil

icon Re: Povezivanje na MySQL server, POMOC!21.05.2008. u 11:16 - pre 193 meseci
Citat:
vlado_036: Probao sam nekoliko (vise od 10) ODBC Wrapper-a ali ni jedan nije hteo da se bez greske kompajlira, svaki za sebe prijavljuje druge greske. Svisu pisani za Visual C++ 6 a ja koristim Visual C++ 9, da li je u tome problem?

Uspeo sam preko CDatabase i CRecordset da iscitavam podatke iz MySQL baze.


Ajde paste-uj compiler greske da se vidi o cemu se radi ...
Ja sam probao taj ODBC wrapper za koji sam ti dao link u VS2005 (MFC 8.0) i prosao je bez problema ...
Desava se uglavnom da su to sitne ispravke koje treba otkloniti
(drugi header-i ,razliciti deklarisani tipovi ili pointeri na neke funkcije itd ..)
Ako ne uspes da iskompajliras imas u tom direktorijumu gsodbc.lib fajl koji treba da ulinkujes u tvoj program i da onda samo pozivas njegove funkcije

Viva lollapalooza
 
Odgovor na temu

vlado_036

Član broj: 108868
Poruke: 8
*.ptt.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!22.05.2008. u 07:50 - pre 193 meseci
Evo gresaka

stmt.cpp(115) : error C2664: 'SQLExecDirectW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(202) : error C2664: 'SQLPrepareW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(509) : error C2664: 'SQLDescribeColW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(742) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(755) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(759) : error C2664: 'GetTimeFormatW' : cannot convert parameter 5 from 'char *' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(879) : error C2664: 'SQLErrorW' : cannot convert parameter 4 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
stmt.cpp(1022) : warning C4018: '<' : signed/unsigned mismatch
stmt.cpp(1039) : warning C4018: '<' : signed/unsigned mismatch
stmt.cpp(1088) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
stmt.cpp(1300) : error C2664: 'SQLNativeSqlW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Columns.cpp
columns.cpp(68) : error C2664: 'SQLColumnsW' : cannot convert parameter 2 from 'UCHAR *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
columns.cpp(117) : error C2664: 'ATL::CStringT<BaseType,StringTraits>::CStringT(const VARIANT &)' : cannot convert parameter 1 from 'const char [2]' to 'const VARIANT &'
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC<wchar_t>
]
Reason: cannot convert from 'const char [2]' to 'const VARIANT'
No constructor could take the source type, or constructor overload resolution was ambiguous
connect.cpp
connect.cpp(44) : error C2664: 'SQLConnectW' : cannot convert parameter 2 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(78) : error C2664: 'SQLDriverConnectW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(126) : error C2664: 'SQLErrorW' : cannot convert parameter 4 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(288) : error C2664: 'SQLTablesW' : cannot convert parameter 6 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(313) : error C2664: 'SQLColumnsW' : cannot convert parameter 6 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(339) : error C2664: 'SQLDataSourcesW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
connect.cpp(352) : error C2664: 'SQLDataSourcesW' : cannot convert parameter 3 from 'unsigned char *' to 'SQLWCHAR *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp
cur.cpp(41) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'
cur.cpp(42) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\string.h(74) : see declaration of 'strcpy'
cur.cpp(43) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\string.h(79) : see declaration of 'strcat'
cur.cpp(49) : error C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(50) : error C2664: 'GetTempFileNameW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(325) : error C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(326) : error C2664: 'GetTempFileNameW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(451) : error C2664: 'DeleteFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(453) : error C2664: 'DeleteFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(584) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(597) : error C2664: 'GetDateFormatW' : cannot convert parameter 5 from 'char [1024]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(601) : error C2664: 'GetTimeFormatW' : cannot convert parameter 5 from 'char *' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
cur.cpp(772) : warning C4018: '<' : signed/unsigned mismatch
cur.cpp(935) : warning C4018: '<' : signed/unsigned mismatch
cur.cpp(1033) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
curex.cpp
curex.cpp(19) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
curex.cpp(28) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
curex.cpp(38) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
excpt.cpp
excpt.cpp(23) : error C2664: 'LoadStringW' : cannot convert parameter 3 from 'char [256]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.adsl-4.sezampro.yu.



+395 Profil

icon Re: Povezivanje na MySQL server, POMOC!22.05.2008. u 09:01 - pre 193 meseci
Projekat ti je definisan da koristi Unicode charset (tj. WCHAR)..
a wrapper podrzava samo Ansi charset (char* )
Ako ti nije preko potreban Unicode promeni umesto "Use Unicode Charset " u Project Properties u Charset -> Use MultiByte Charset ..
i radice ti ...

Ako ti je bas potreban Unicode u tvom projektu onda je situacija malo teza ...
wrapper klase moras preraditi da koriste Unicode karaktere (promeni sve char* u wchar_t* )







Viva lollapalooza
 
Odgovor na temu

vlado_036

Član broj: 108868
Poruke: 8
*.ptt.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!22.05.2008. u 11:39 - pre 193 meseci
Zamenio sam sve char* u wchar_t*.

Sada imam sledece greske :

Compiling...
Columns.cpp
columns.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
columns.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
connect.cpp
connect.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
connect.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
cur.cpp
cur.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
cur.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
curex.cpp
curex.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
curex.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
curidx.cpp
curidx.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
curidx.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
excpt.cpp
excpt.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
excpt.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
stmt.cpp
stmt.cpp : error C2471: cannot update program database 'e:\program\vp\vp\debug\vc90.pdb'
stmt.cpp : fatal error C1083: Cannot open program database file: 'e:\program\vp\vp\debug\vc90.pdb': No such file or directory
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.adsl-4.sezampro.yu.



+395 Profil

icon Re: Povezivanje na MySQL server, POMOC!22.05.2008. u 11:46 - pre 193 meseci
Uradi jedan Clean Solution pa Rebuild ..
*.pdb je fajl gde Visual Studio smesta podatke za debug-ovanje

Takodje pogledaj da li jos negde u kodu imas npr :
func("SQL UPIT") -> func(_T("SQL UPIT"));
_T() je makro koji transformise string pod navodnicima u unicode string




[Ovu poruku je menjao deerbeer dana 22.05.2008. u 13:03 GMT+1]
Viva lollapalooza
 
Odgovor na temu

vlado_036

Član broj: 108868
Poruke: 8
*.ptt.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!23.05.2008. u 11:54 - pre 193 meseci
Ponovo sam presao sve fajlove i zamenio char sa wchar_t i sad je OK.
Problem je sad konekcija, ubacio sam makto _T() na svim mestima gde se koriste SQL upiti.

dbCon.connect(_T("MyODBC"), _T("root"), _T("xxx"));

Evo greske koja se javlja kada pokusam da uspostavim konekciju :

error LNK2019: unresolved external symbol "public: void __thiscall CGOdbcConnect::connect(wchar_t const *,wchar_t const *,wchar_t const *)" (?connect@CGOdbcConnect@@QAEXPB_W00@Z) referenced in function "public: void __thiscall CPrijemDlg::OnBnClickedBnSnimi(void)" (?OnBnClickedBnSnimi@CPrijemDlg@@QAEXXZ)
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.adsl-3.sezampro.yu.



+395 Profil

icon Re: Povezivanje na MySQL server, POMOC!23.05.2008. u 12:12 - pre 193 meseci
Ako si komponentu iskompajlirao kao DLL ili kao static LIB ..
onda je dodaj u Linker Modules njenu putanju ....

Ako si source od komponente ubacio u sam projekat negde
pogledaj da li je source fajl na toj putanj.

Jer ova greska ukazuje na to da imas header-e (zato ti compile prolazi)
a nemas source code u toku linkovanja ....



Viva lollapalooza
 
Odgovor na temu

srecko.srecko
Nis

Član broj: 217061
Poruke: 3
*.smin-1.sezampro.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!22.03.2009. u 12:17 - pre 183 meseci
Evo moj kod za povezivanje sa mysql. Pisan je u c i koristi mysql.h koji ide uz instalaciju
sa MySql-om
Ja sam malo modifikovao derekov fajl koji sam skinuo sa interneta ali sam tu stavio i njegov i moj.

Code:

/*******************************************
Using Visual C++ 6.0 to connect to MySQL
Posted by: Derek Keeler () 
Date: October 16, 2005 03:31AM


Hi all. 

Probably been tutorialized like crazy here and across the Internets, 
but since I couldn't find it anywhere (at least with the google-ing that I did tonight) I figured I'd post my experience doing this here. 

First some system notes: 

MySQL 4.0.22 running on Linux (Gentoo) server 
'mysql Ver 14.7 Distrib 4.1.12a, for Win32 (ia32)' running on local machine (Windows XP SP2) 
Visual C++ ver 6.0 (Service pack 6) 


  The program: 

Start Visual C++ 
Create a new Win32 console project (File->New and select 'Win32 Console Application') 
Select the option to create a 'A simple application' and hit Ok 
Under Project->Settings change the following for your 'Settings for Win32 Debug' 

Tab: C/C++ 
-------------- 
[ Category: Preprocessor ] 
Additional include directories: 
<path to your Mysql installation>\include 

[ Category: Code Generation ] 
Use run-time library: 
Multithreaded 

[ Category: Precompiled Headers ] 
select 'Not using precompiled headers' 

Tab: Link 
---------- 
[ Category: Input ] 
Object/library modules: (append the following) 
wsock32.lib mysqlclient.lib libmysql.lib mysys.lib 

Ignore libraries: 
LIBCMTD.lib 

Additional library path: 
<path to your MySql installation>\lib\debug 

Then hit Ok. Now its time for code. 

In the source file that the 'main.cpp', replace what is there with the following. 

U slucaju da pravi problema iz Tab:Link Object/library modules: (append the following) 
izbaci mysqlclient.lib

Ako postoji jos jedna main funkcija u drugom fajlu koji je 
napravio Visual C++ obrisi je

In the source file that the 'main.cpp', replace what is there with the following. 

==================== SOURCE FILE CONTENTS ==================== 

#include <stdio.h> 
#define W32_LEAN_AND_MEAN 
#include <winsock2.h> 
#include "mysql.h" 

// change these to suit your setup 
#define TABLE_OF_INTEREST "some_table" 
#define SERVER_NAME "mysql_server" 
#define DB_USER "user" 
#define DB_USERPASS "pa55w0rd" 
#define DB_NAME "db_name" 

// prototypes 
void showTables(MYSQL*); 
void showContents(MYSQL*,const char*); 

int main(int argc, char* argv[]) 

MYSQL *hnd=NULL; // mysql connection handle 
const char *sinf=NULL; // mysql server information 

hnd = mysql_init(NULL); 
if (NULL == mysql_real_connect(hnd,SERVER_NAME,DB_USER,DB_USERPASS,DB_NAME,0,NULL,0)) 

fprintf(stderr,"Problem encountered connecting to the %s database on %s.\n",DB_NAME,SERVER_NAME); 

else 

fprintf(stdout,"Connected to the %s database on %s as user '%s'.\n",DB_NAME,SERVER_NAME,DB_USER); 
sinf = mysql_get_server_info(hnd); 

if (sinf != NULL) 

fprintf(stdout,"Got server information: '%s'\n",sinf); 
showTables(hnd); 
showContents(hnd,TABLE_OF_INTEREST); 

else 

fprintf(stderr,"Failed to retrieve the server information string.\n"); 


mysql_close(hnd); 


return 0; 


void showTables(MYSQL *handle) 

MYSQL_RES *result=NULL; // result of asking the database for a listing of its tables 
MYSQL_ROW row; // one row from the result set 

result = mysql_list_tables(handle,NULL); 
row = mysql_fetch_row(result); 
fprintf(stdout,"Tables found:\n\n"); 
while (row) 

fprintf(stdout,"\t%s\n",row[0]); 
row = mysql_fetch_row(result); 

mysql_free_result(result); 

fprintf(stdout,"\nEnd of tables\n"); 

return; 


void showContents 

MYSQL *handle, 
const char *tbl 


MYSQL_RES *res=NULL; // result of querying for all rows in table 
MYSQL_ROW row; // one row returned 
char sql[1024], // sql statement used to get all rows 
commastr[2]; // to put commas in the output 
int i,numf=0; // number of fields returned from the query 

sprintf(sql,"select * from %s",tbl); 
fprintf(stdout,"Using sql statement: '%s' to extract all rows from the specified table.\n",sql); 

if (!mysql_query(handle,sql)) 

res = mysql_use_result(handle); 
if (res) 

numf = mysql_num_fields(res); 
row = mysql_fetch_row(res); 
fprintf(stdout,"Rows returned:\n\n"); 
while (row) 

commastr[0]=commastr[1]=(char)NULL; 
for (i=0;i<numf;i++) 

if (row[i] == NULL) 

fprintf(stdout,"%sNULL",commastr); 

else 

fprintf(stdout,"%s%s",commastr,row[i]); 

commastr[0]=','; 

fprintf(stdout,"\n"); 

row = mysql_fetch_row(res); 

fprintf(stdout,"\nEnd of rows\n"); 

mysql_free_result(res); 

else 

fprintf(stderr,"Failed to use the result acquired!\n"); 


else 

fprintf(stderr,"Failed to execute query. Ensure table is valid!\n"); 


return; 


==================== END OF SOURCE FILE ==================== 


Altogether, this is an exceedingly simple example, and has very little in terms of help for the inexperienced. Regardless, I hope this helps the next poor soul who can't seem to get it together with google. 

The libraries to include, and the extra's to include from Windows itself were my biggest hurdle. (Oh yes, and the setting to 'Multithreaded' took me a bit to figure out too). 

Good luck to everyone, and sorry I can't format this message a bit better. Just copy/paste the code above and tab until pretty. 

--derek

******************************************************************
*/
/****Ovo ispod je modifikovan derekov fajl i preveden**********/




#include <stdio.h> 
#define W32_LEAN_AND_MEAN 
#include <winsock2.h> 
#include <mysql.h> /*Ovo je postavljeno sa "< >" jer sam ja ukljucio mysql.h kao deo da moze da bude pretrazen iz prevodioca inace je tu putanje do foldera gde je instaliran
mysql i gde se i nalazi mysql.h ***************
*/

// change these to suit your setup 
#define TABLE_OF_INTEREST "student" 
#define SERVER_NAME "localhost" 
#define DB_USER "root" 
#define DB_USERPASS "srle" //ako nemas pasvord ostavi samo ""
#define DB_NAME "ucenje" 




// prototypes 
void showTables(MYSQL*); 
void showContents(MYSQL*,const char*); 
void showDatabases(MYSQL*);
void showPravljenjeTabele(MYSQL*);

int main(int argc, char* argv[]) 

  
    
  MYSQL *hnd=NULL; // mysql connection handle 
  const char *sinf=NULL; // mysql server information 

  hnd = mysql_init(NULL); 
  if (NULL == mysql_real_connect(hnd,SERVER_NAME,DB_USER,DB_USERPASS,DB_NAME,0,NULL,0)) 
  { 
    fprintf(stderr,"Problem encountered connecting to the %s database on %s.\n",DB_NAME,SERVER_NAME); 
  } 
  else 
  { 
    fprintf(stdout,"Connected to the %s database on %s as user '%s'.\n",DB_NAME,SERVER_NAME,DB_USER); 
    sinf = mysql_get_server_info(hnd); 

    /***************************************************/
    /* Get host, server and protocol info */
    printf("Host: %s\n", mysql_get_host_info(hnd));
    printf("Server: %s\n", mysql_get_server_info(hnd));
    printf("Protocol: %d\n", mysql_get_proto_info(hnd));

    
    

    /****************************************************/


    if (sinf != NULL) 
    { 
      fprintf(stdout,"Got server information: '%s'\n",sinf); 
      showTables(hnd); 
      showContents(hnd,TABLE_OF_INTEREST);
      showDatabases(hnd);
      showPravljenjeTabele(hnd);
      /* Ja sam napravio databazu imena_gradova */
      mysql_query(hnd, "CREATE DATABASE imena_gradova");
    } 
    else 
    { 
      fprintf(stderr,"Failed to retrieve the server information string.\n"); 
    } 

    mysql_close(hnd); 
  } 

  
 

  return 0; 


void showTables(MYSQL *handle) 

    MYSQL_RES *result=NULL; // result of asking the database for a listing of its tables 
    MYSQL_ROW row; // one row from the result set 
 
    

    result = mysql_list_tables(handle,NULL); 
    row = mysql_fetch_row(result); 
    fprintf(stdout,"Tables found:\n\n"); 
    while (row) 
    { 
      fprintf(stdout,"\t%s\n",row[0]); 
      row = mysql_fetch_row(result); 
    } 
    
    
    
    
    mysql_free_result(result); 

    fprintf(stdout,"\nEnd of tables\n"); 

  return; 





void showContents ( MYSQL *handle, const char *tbl ) 

  MYSQL_RES *res=NULL; // result of querying for all rows in table 
  MYSQL_ROW row; // one row returned 
  char sql[1024], // sql statement used to get all rows 
commastr[2]; // to put commas in the output 
int i,numf=0; // number of fields returned from the query 

sprintf(sql,"select * from %s",tbl); 
fprintf(stdout,"Using sql statement: '%s' to extract all rows from the specified table.\n",sql); 

if (!mysql_query(handle,sql)) 

  res = mysql_use_result(handle); 
  if (res) 
  { 
    numf = mysql_num_fields(res); 
    row = mysql_fetch_row(res); 
    fprintf(stdout,"Rows returned:\n\n"); 
    while (row) 
    { 
      commastr[0]=commastr[1]=(char)NULL; 
      for (i=0;i<numf;i++) 
      { 
        if (row[i] == NULL) 
        { 
          fprintf(stdout,"%sNULL",commastr); 
        } 
        else 
        { 
          fprintf(stdout,"%s%s",commastr,row[i]); 
        } 
        commastr[0]=','; 
      } 
      fprintf(stdout,"\n"); 

      row = mysql_fetch_row(res); 
    } 
    fprintf(stdout,"\nEnd of rows\n"); 

    mysql_free_result(res); 
  } 
  else 
  { 
     fprintf(stderr,"Failed to use the result acquired!\n"); 
  } 

else 

  fprintf(stderr,"Failed to execute query. Ensure table is valid!\n"); 


return; 


/***********************************************/
void showDatabases(MYSQL *handle)
{
    
    MYSQL_RES  *resource; /*result of querying for all rows in table*/
    MYSQL_ROW   result;  /* one row returned  */

    /* Execute our SHOW DATABASES statement */
    mysql_query(handle, "SHOW DATABASES");
    
    /* Resource structure with the rows of data from SHOW DATABASES */
    resource = mysql_use_result(handle);
    printf("Databases:\n\n");
    
    /* Fetch & print each row */
    while((result = mysql_fetch_row(resource)))
    {
        printf("%s\n", result[0]);
    }

    /************************************/

    /* prikazivanje tabela*/
    mysql_query(handle, "show tables");

    /*with rows of returned data. */
        resource = mysql_use_result(handle);
    printf("\nTabele u bazi ucenje:\n\n");
    
    /* Fetch & print each row */
    while((result = mysql_fetch_row(resource)))
    {
        printf("%s\n", result[0]);
    }



     return ;

}

/**********************************************************/




void showPravljenjeTabele(MYSQL *ruk)
{

    //napravi tabelu test_table
    #define DROP_SAMPLE_TABLE "DROP TABLE IF EXISTS test_table"

    #define CREATE_SAMPLE_TABLE "CREATE TABLE test_table(col1 INT,\
                                                 col2 VARCHAR(40),\
                                                 col3 SMALLINT,\
                                                 col4 TIMESTAMP)"

    
    MYSQL_RES  *resource; /*result of querying for all rows in table*/
    MYSQL_ROW   result;  /* one row returned  */

    /* Execute our SHOW DATABASES statement */
    mysql_query(ruk, "show databases");
    
    /* Resource structure with the rows of data from SHOW DATABASES */
    resource = mysql_use_result(ruk);
    printf("Databases:\n\n");
    
    /* Fetch & print each row */
    while((result = mysql_fetch_row(resource)))
    {
        printf("%s\n", result[0]);
    }

    /************************************/
     /************************************/

    /* prikazivanje tabela*/
    mysql_query(ruk, "show tables");

    /*with rows of returned data. */
        resource = mysql_use_result(ruk);
    printf("\nTabele u bazi ucenje:\n\n");
    
    /* Fetch & print each row */
    while((result = mysql_fetch_row(resource)))
    {
        printf("%s\n", result[0]);
    }

   /****************************************************/
    /****pravljenje nove tabele*********/
    if (mysql_query(ruk, DROP_SAMPLE_TABLE))
    {
      fprintf(stderr, " DROP TABLE failed\n");
      fprintf(stderr, " %s\n", mysql_error(ruk));
      exit(0);
    }


    if (mysql_query(ruk, CREATE_SAMPLE_TABLE))
    {
     fprintf(stderr, " CREATE TABLE failed\n");
     fprintf(stderr, " %s\n", mysql_error(ruk));
     exit(0);
    }
    
    
    /***********************************/
    /*******Prikazivanje sadrzaja tabele************/
    /*
    void showContents ( MYSQL *handle, const char *tbl )
    */
     mysql_query(ruk, CREATE_SAMPLE_TABLE);
     #define TABELA_KOJA_MI_TREBA "ocene"

    /*Prikazivanje sadrzaja tabele pozivanjem funkcije*/ 
    showContents (ruk, TABELA_KOJA_MI_TREBA );
     /************************************/

    /* prikazivanje tabela*/
    mysql_query(ruk, "describe student");

    /*with rows of returned data. */
        resource = mysql_use_result(ruk);
    printf("\n Kolone u tabeli ocene:\n\n");
    
    /* Fetch & print each row */
    while((result = mysql_fetch_row(resource)))
    {
        printf("%s\n", result[0]);
    }

   /**************************************************/

    return;
}



[Ovu poruku je menjao srecko.srecko dana 22.03.2009. u 13:54 GMT+1]

[Ovu poruku je menjao X Files dana 22.03.2009. u 14:10 GMT+1]
Prikačeni fajlovi
 
Odgovor na temu

srecko.srecko
Nis

Član broj: 217061
Poruke: 3
*.smin-1.sezampro.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!22.03.2009. u 13:14 - pre 183 meseci
Napomena uz prethodni odgovor:
Ime servera, baza i password kao i ime tabela zavise od vaseg podesavanja tako da ih menjate u skladu s tim
 
Odgovor na temu

Goran Arandjelovic
Beograd

Član broj: 29116
Poruke: 387
*.rcub.bg.ac.yu.



+9 Profil

icon Re: Povezivanje na MySQL server, POMOC!22.03.2009. u 13:41 - pre 183 meseci
MySQL++
http://tangentsoft.net/mysql++/

Radi odlično sa STL-om... koristio sam ga uglavnom sa g++-om,
ali radi sa VC++-om.
 
Odgovor na temu

kiklop74
Darko Miletić
Buenos Aires

Član broj: 78422
Poruke: 569
*.fibertel.com.ar.

Sajt: ar.linkedin.com/pub/darko..


+13 Profil

icon Re: Povezivanje na MySQL server, POMOC!22.03.2009. u 22:39 - pre 183 meseci
Moja preporuka je SOCI
http://soci.sourceforge.net/

Takodje jako lepo radi sa STL-om i sa boost bibliotekom.
Tko leti vrijedi
 
Odgovor na temu

srecko.srecko
Nis

Član broj: 217061
Poruke: 3
*.smin-1.sezampro.yu.



Profil

icon Re: Povezivanje na MySQL server, POMOC!28.03.2009. u 15:44 - pre 183 meseci
soci je u redu, ali milslim kad vec koristis MySql onda je dobro koristiti njihovu biblioteku.
Iz ovog primera moze da se vidi kako da napravis MySql bazu koristeci C, ali i da se nauci kako da se povezes na niskom nivou. Kome treba moze dosta da pomogne.
 
Odgovor na temu

kiklop74
Darko Miletić
Buenos Aires

Član broj: 78422
Poruke: 569
*.fibertel.com.ar.

Sajt: ar.linkedin.com/pub/darko..


+13 Profil

icon Re: Povezivanje na MySQL server, POMOC!29.03.2009. u 00:48 - pre 183 meseci
Zasto? To je kao da si rekao zasto lako kad moze komplikovano.

soci koristi ispod haube mysql biblioteku i oslobadja korisnika brige oko svih suvisnih detalja.


Tko leti vrijedi
 
Odgovor na temu

MarkoBalkan

Član broj: 141124
Poruke: 1624
...135.24-dsl.net.metronet.hr.



+19 Profil

icon Re: Povezivanje na MySQL server, POMOC!30.03.2009. u 09:30 - pre 183 meseci
koristi mysql c api.


http://www.zetcode.com/tutorials/mysqlcapitutorial/


ja odbc izbjegavam jer mi se ne sviđa.
 
Odgovor na temu

[es] :: C/C++ programiranje :: Povezivanje na MySQL server, POMOC!

Strane: 1 2

[ Pregleda: 8459 | Odgovora: 20 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.