Link to home
Start Free TrialLog in
Avatar of sureshp
sureshp

asked on

Small code for inserting....

Hi all,
This is a simple request.
I need a small program in C, which cam be used to insert values in the table. The database is used for this is MySQL and run this program under Linux.

So i request you to post a small C code here.

Say database name : test
table one :- fields name, age

Thanks in advance.
Avatar of gj62
gj62

Here's how to connect:

MYSQL mysql;

mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
    fprintf(stderr, "Failed to connect to database: Error: %s\n",
          mysql_error(&mysql));
}
For more, the C API code is distributed with MySQL. It is included in the mysqlclient library and allows C programs to access a database.

Many of the clients in the MySQL source distribution are written in C. If you are looking for examples that demonstrate how to use the C API, take a look at these clients. You can find these in the clients directory in the MySQL source distribution.

You can then adapt an example, easier than us trying to guess exactly what you need.

You can also look at the C API online at:

http://www.mysql.com/doc/en/C.html
Avatar of sureshp

ASKER

gj62,

Thanks for your response.
I am new to this area. I didn't write any c program using a database connection.
So could you please post a small program (full code) that can be used to insert some values into a table. It will be more useful for me to follow.
Thanks for your help.
 
ASKER CERTIFIED SOLUTION
Avatar of gj62
gj62

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sureshp

ASKER

Thanks for your help.
Could you pls post a complete code here?
Regards
I need to know a bit more about exactly what you want to do to post complete code...