我想插入一个字段到MySQL数据库,但它不起作用。mysql查询插入不工作
我试图改变使用只是“插入到图像”,使用查询字符串确保字符串文字。 我看着here尝试了解语法是否有所不同或什么。
我认为Iam根据API来做。
Here我的设置
从出来把我得到
i = 1
MySQL Tables in mysql database:
images
这里是代码。
任何想法?
/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
//set the password for mysql server here
char *password = "********";
char *database = "myDB";
conn = mysql_init(NULL);
if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
/* send SQL query */
if (mysql_query(conn, "show tables") == 1)
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
int i = mysql_query(conn ,"INSERT INTO `myDB`.`images` (`id`, `date`, `path`) VALUES (NULL, CURRENT_TIMESTAMP, 'mypath/foo/bar')");
printf("i = %d \n", i);
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
{
printf("%s \n", row[0]);
}
/* close connection */
mysql_free_result(res);
mysql_close(conn);
return 0;
}
如果只有mysql的库有一个函数来获取信息的错误,http://dev.mysql.com/doc/refman/5.7/en/mysql -error.html。顺便说一句,你忘了“;”。 – Stargateur
必须提交'insert'查询。如果不是,则不执行插入。它不会产生任何可以取得的结果。 – DyZ
你能举一个例子@DYZ – Jacob