LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-06-2015, 01:15 AM   #1
chenjintao_ii
LQ Newbie
 
Registered: Dec 2011
Posts: 27

Rep: Reputation: Disabled
how to use mysql api in C language


I already get data from mysql server by followed functions:
mysql_stmt_init();
mysql_stmt_prepare();
mysql_stmt_execute();
mysql_stmt_bind_result();
mysql_stmt_store_result();

then I want to use the API mysql_fetch_rows(MYSQL_RES *res) instead of mysql_stmt_fetch(MYSQL_STMT *stmt) to fetch rows, any one can tell is there any solution that can translate struct MYSQL_STMT into struct MYSQL_RES?


thanks in advance.
 
Old 02-06-2015, 01:28 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
sorry, I do not understand it. mysql_stmt is the statement you want to execute and mysql_res is the result of the execution. So what do you really mean by that translation?
also please read the official documentation: mysql-fetch-row, mysql-stmt-execute, mysql-stmt-fetch including their examples
here you can find some additional examples about the usage: https://gist.github.com/hoterran/6365915
 
Old 02-06-2015, 01:59 AM   #3
chenjintao_ii
LQ Newbie
 
Registered: Dec 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
sorry, I do not understand it. mysql_stmt is the statement you want to execute and mysql_res is the result of the execution. So what do you really mean by that translation?
also please read the official documentation: mysql-fetch-row, mysql-stmt-execute, mysql-stmt-fetch including their examples
here you can find some additional examples about the usage: https://gist.github.com/hoterran/6365915
Thank you for your reply.

There are tow set of APIs that can get rows from mysql server, one is:
mysql_real_query()/mysql_store_result()/mysql_fetch_row(),
and the other one is:
mysql_stmt_init()/mysql_stmt_prepare()/mysql_stmt_execute()/mysql_stmt_bind_result()/mysql_stmt_store_result()/mysql_stmt_fetch()

I have already get all result set from mysql server by using mysql_stmt_store_result(), but how to use mysql_fetch_row() to get one row from the result set?
 
Old 02-06-2015, 04:27 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
see the last link about working examples: https://gist.github.com/hoterran/6365915
 
Old 02-09-2015, 07:36 PM   #5
chenjintao_ii
LQ Newbie
 
Registered: Dec 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
see the last link about working examples: https://gist.github.com/hoterran/6365915
sigh... I cannot load this web page because of the GFW. After reading some API's source code, I found that it is not a good solution that using one set of API to get result set but using the other set of API to get every row's data.

I must search an other way to fulfill task.

Thanks all the same, pan64.
 
Old 02-09-2015, 08:09 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997Reputation: 1997
I think the reference you need is here, you can select your version of the manual from the left sidebar.

I think that the API function you are looking for is actually mysql_stmt_fetch(). Can you say why that does not work for you?

Last edited by astrogeek; 02-09-2015 at 08:35 PM.
 
Old 02-09-2015, 10:26 PM   #7
chenjintao_ii
LQ Newbie
 
Registered: Dec 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
I think the reference you need is here, you can select your version of the manual from the left sidebar.

I think that the API function you are looking for is actually mysql_stmt_fetch(). Can you say why that does not work for you?
thanks for your reply, and mysql_stmt_fetch() can work perfectly.
My origin code is as followed:
int SelectTableRecord(char *szSql, MYSQL_RES *res)
// szSql is SQL such as "select * from table"

In this API, mysql_read_query()/mysql_store_result() is executed, the result set is pointed by input parameter 'res'.
Now I want to change the way that get the result set by using mysql_stmt_execute() instead of mysql_read_query(), without changing the API's parameters.
It means I have to change the result set from struct MYSQL_STMT to struct MYSQL_RES, maybe it's a stupid idea...
 
  


Reply

Tags
api, mysql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for return value from a API call in C language kushalkoolwal Programming 5 08-19-2008 05:55 PM
MySQL Client API I_AM Linux - Newbie 1 06-27-2005 03:52 AM
mysql client api I_AM Linux - Newbie 1 06-24-2005 12:48 AM
msql++ c++ api for mysql nakkaya Linux - Software 0 04-19-2003 04:56 PM
c++ and mysql api nakkaya Programming 4 03-29-2003 12:10 AM


All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration