00001 00002 #include <stdlib.h> 00003 #include <stdio.h> 00004 #include <string.h> 00005 00006 #include "01-connect.h" 00007 #include <mysql/mysql.h> 00008 00009 int main (int argc, char *argv[]) 00010 { 00011 MYSQL *connection1; 00012 int result; 00013 int result1; 00014 00015 connection1 = mysql_init(NULL); 00016 if (mysql_real_connect (connection1, "localhost", "ain", "ain151", "atm", 0, NULL, 0)) 00017 { 00018 printf ("Connection successful\n"); 00019 00020 result = mysql_query (connection1, "insert into user values(1234, 'Ain', '0101102','10000.00')"); 00021 00022 result1 = mysql_query (connection1, "insert into user values(5678, 'Laila', '0101109','5000.00')"); 00023 00024 if (result==0 && result1==0) 00025 { 00026 printf ("Row inserted successfully.\n"); 00027 } 00028 else 00029 { 00030 fprintf (stderr, "Could not insert data as %d: %s\n", 00031 mysql_errno (connection1), 00032 mysql_error (connection1)); 00033 mysql_close (connection1); 00034 exit(EXIT_FAILURE); 00035 } 00036 00037 mysql_close (connection1); 00038 } 00039 else 00040 { 00041 fprintf (stderr, "Connection failed\n"); 00042 if (mysql_errno (connection1)) 00043 { 00044 fprintf (stderr, "Connection error %d: %s\n", 00045 mysql_errno (connection1), 00046 mysql_error (connection1)); 00047 } 00048 } 00049 00050 exit(EXIT_SUCCESS); 00051 return 0; 00052 }