我想在我的C程序中使用mysql API插入計算出來的變量。儘管嘗試所有類型的技巧(單引號,雙引號,查詢佔位符),我無法輸入數據。所使用的庫是:使用c在mysql數據庫中插入變量
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <netinet/in.h>
#include <math.h>
#include <my_global.h>
#include <mysql.h>
代碼的相關位是
MYSQL *con = mysql_init(NULL);
if (mysql_real_connect(con, "localhost", "test", "test123",
"transport", 0, NULL, 0) == NULL)
{
finish_with_error(con);
}
if (mysql_query(con, "INSERT INTO gps_points(vehicle_id,lat,lon,speed) VALUES(unit_id_dec,lat,lon,speed_float)"))
{
finish_with_error(con);
}
mysql_close(con);
我收到以下錯誤:
Unknown column 'unit_id_dec' in 'field list'
使用的編譯選項是:
sudo gcc socketListen.c -o listenSock -lm `mysql_config --cflags --libs`
任何解決方案?
看看http://dev.mysql.com/doc/refman/5.7/en/c- api-prepared-statement-function-overview.html – dbush