-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert1.c
More file actions
40 lines (30 loc) · 838 Bytes
/
insert1.c
File metadata and controls
40 lines (30 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdlib.h>
#include <stdio.h>
#include "mysql.h"
int main(int argc, char *argv[])
{
MYSQL my_connection;
int res;
mysql_init(&my_connection);
if (mysql_real_connect(&my_connection, "localhost", "rick", "secret","TEST", 0, NULL, 0))
{
printf("Connection success.\n");
res=mysql_query(&my_connection,"INSERT INTO children(fname,age) VALUES('Ann',3)");
if(!res){
printf("Inserted %lu rows\n",(unsigned long)mysql_affected_rows(&my_connection));
}
else{
fprintf(stderr, "Insert error %d: %s\n", mysql_errno(&my_connection),mysql_error(&my_connection));
}
mysql_close(&my_connection);
}
else
{
fprintf(stderr,"Connection failed\n");
if(mysql_errno(&my_connection))
{
fprintf(stderr,"Connection error %d: %s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
}
return EXIT_SUCCESS;
}