Re: Stored Procedures in c
Hi thanks for having interest. Here is the code. NOne ofthe insert is working
if i hardcode myprocinsert it works but it is not working for variabl;es.
/* Program to insert data in MYSQL */
#include<stdio.h>
#include<stdlib.h>
#include<mysql.h>
#include<string.h>
int main(int argc, char **argv)
{
MYSQL *conn;
char *server = "localhost";
char *user = "root";
char *password ="1234"; /* set me first */
int a=101;
int b=10;
int c =10;
conn=mysql_init(NULL);
if(conn==NULL){
printf("Error %u :%s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
/* Connect to database */
if(mysql_real_connect(conn,server,user,password,"db",0,NULL,0) == NULL) {
printf("Error %u : %s /n",mysql_errno(conn), mysql_error(conn));
exit(1);
}
/* send SQL query */
//_query(conn,"insert into Sensor_Update values(100,100,100)");
// Calling a stored procedure
if(mysql_query(conn,"insert into Sensor_Update values(@a,@b,@c)")!=0)
{
printf("%s \n ",mysql_error(conn));
}
if(mysql_query(conn,"CALL myprocInsert(@a,@b,@c)")!=0)
{
printf("%s \n ",mysql_error(conn));
}
//call myprocInsert(@a,@b,@c);
mysql_close(conn);
}