- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: mysql sample code
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-06-2004 08:31 PM
тАО12-06-2004 08:31 PM
Is anybody write mysql application through it's C API. Would you mind send me the code about insert. Thank you!! Here is the query sample code I write!!
#include
#include
int main()
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char *query,*input;
int t;
unsigned long r;
char *insert_value[2];
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,"localhost","mysql1","mysql1","mysql1",0,NULL,0))
printf("Error connecting to database:%s\n",mysql_error(&mysql));
else
printf("Mysql Connected ...\n");
query="select * from test1";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error makeing query:%s\n",mysql_error(&mysql));
else
printf("Query made.....\n");
res=mysql_store_result(&mysql);
printf("the number rows of result set is %u\n",(unsigned long)mysql_num_rows(res));
for(r=0;r<(unsigned long)mysql_num_rows(res);r++)
{
row=mysql_fetch_row(res);
if(row<0) break;
for(t=0;t
printf("%s ",row[t]);
insert_value[t]=row[t];
}
printf(" name is %s, and salary is %d\n",insert_value[0],atoi(insert_value[1]));
printf("\n");
}
mysql_free_result(res);
mysql_close(&mysql);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-06-2004 11:11 PM
тАО12-06-2004 11:11 PM
Solutionhttp://dev.mysql.com/doc/mysql/en/mysql_info.html
http://dev.mysql.com/doc/mysql/en/mysql_affected_rows.html
http://dev.mysql.com/doc/mysql/en/libmysqld_example.html
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2004 01:34 PM
тАО12-07-2004 01:34 PM
Re: mysql sample code
I was misleading by the function name "mysql_real_query". You could use insert,delete, update, select for this function.The follwoing is the sample code for insert, update.
#include
#include
int main()
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char *query;
int t;
unsigned long r;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,"localhost","mysql1","mysql1","mysql1",0,NULL,0))
printf("Error connecting to database:%s\n",mysql_error(&mysql));
else
printf("Mysql Connected ...\n");
query="insert into test values('insert')";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making insert table test:%s\n",mysql_error(&mysql));
else
printf("Insert made.to test table....\n");
query="update test set name='update' where name='insert'";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making update table test:%s\n",mysql_error(&mysql));
else
printf("Update made.to test table....\n");
query="select * from test";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error makeing query:%s\n",mysql_error(&mysql));
else
printf("Query made.....\n");
res=mysql_store_result(&mysql);
printf("the number rows of result set is %u\n",(unsigned long)mysql_num_rows(res));
for(r=0;r<(unsigned long)mysql_num_rows(res);r++)
{
row=mysql_fetch_row(res);
if(row<0) break;
for(t=0;t
printf("\n");
}
mysql_free_result(res);
mysql_close(&mysql);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2004 12:49 PM
тАО12-09-2004 12:49 PM
Re: mysql sample code
#include
#include
int main()
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char *query;
int t;
unsigned long r;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,"localhost","mysql1","mysql1","mysql1",0,NULL,0))
printf("Error connecting to database:%s\n",mysql_error(&mysql));
else
printf("Mysql Connected ...\n");
/* query="insert into test values('insert')";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making insert table test:%s\n",mysql_error(&mysql));
else
printf("Insert made.to test table....\n");
query="update test set name='update' where name='insert'";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making update table test:%s\n",mysql_error(&mysql));
else
printf("Update made.to test table....\n"); */
// query="start transaction";
query="set autocommit=0";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making start transactions:%s\n",mysql_error(&mysql));
else
printf("Transaction start.....\n");
query="delete from test where name='├е┬╝┬╡├е ├з '";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making delete operation:%s\n",mysql_error(&mysql));
else
printf("Delete made.....\n");
query="delete from test1 where name='├е┬╝┬╡├е ├з '";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making delete operation:%s\n",mysql_error(&mysql));
else
printf("Delete made.....\n");
query="rollback";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making rollback operation:%s\n",mysql_error(&mysql));
else
printf("Rollback delete made.....\n");
query="select * from test1";
t=mysql_real_query(&mysql,query,(unsigned int)strlen(query));
if(t)
printf("Error making query:%s\n",mysql_error(&mysql));
else
printf("Query made.....\n");
res=mysql_store_result(&mysql);
printf("the number rows of result set is %u\n",(unsigned long)mysql_num_rows(res));
for(r=0;r<(unsigned long)mysql_num_rows(res);r++)
{
row=mysql_fetch_row(res);
if(row<0) break;
for(t=0;t
printf("\n");
}
mysql_free_result(res);
mysql_c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-09-2004 12:50 PM
тАО12-09-2004 12:50 PM