this is senthil...
i'm now working in the field of VC++...
i want to connect a mysql database...
just now tried to retrieve rows from a simple
mysql database by using VC++
My database is like this...
---------------
Name roll no
--------------
asd 101
dff 102
sdf 103
fdf 104
dfd 105
i have used the following codings for connecting the database..
And the output also comes clearly.. No probs for the output..
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include <mysql.h>
- #include <conio.h>
- #include <windows.h>
- #include<string.h>
- #define host "192.168.0.2"
- #define username "root"
- #define password ""
- #define database "senthil"
- void main()
- {
- MYSQL *conn;
- conn = mysql_init(NULL);
- mysql_real_connect(conn,host,username,password,database,0,NULL,0);
- MYSQL_RES *res_set;
- MYSQL_ROW row;
- unsigned int i=0;
- mysql_query(conn,"SELECT * FROM sen");
- res_set = mysql_store_result(conn);
- unsigned int numrows = mysql_num_rows(res_set);
- while ((row = mysql_fetch_row(res_set))!= NULL)
- {
- i=0;
- printf("%s\t", row[i]!=NULL? row[i]:"NULL");
- i++;
- printf("%s\n", row[i]!=NULL? row[i]:"NULL");
- }
- mysql_close(conn);
- getch();
- }
row[1]= 101,102,....
Here MYSQL_ROW row; -return data as array of strings
I also used the following codings for fetching a single field from the database by using
the following codings....
For example if i want to fetch 'sdf' field from the database
i gave the condition like this in select statement...
mysql_query(conn,"SELECT * FROM sen where Name='sdf'");
and here also the output comes clearly..
But i dont know how to fetch from a specific row...
for example...
i dont want the first two rows.... and if i want to fetch from
the third row only! what condition shall i give for this?
Very important point is that,
here MYSQL_ROW row; -return data as array of strings,
ie rows can only be returned as strings...
ie the first row will be return as a string..(asd,dff,....)
and the second row wil be returned as another string...(101,102)..
But i want to split that row....
How can i do that?
plzz explain me, this concept is going to be used for my project....
itz very important for me....
Can any one plzz reply me...
thanks...
senthil