0
我想插入一个本地html文件'test.html'到mysql中的表中,我正在通过嵌入式c代码在mysql服务器上工作。不过,当我尝试插入该HTML文件时,我得到了访问被拒绝的错误。在这条线GRANT FILE ON *.* TO 'james'@'localhost'
:Html文件不插入Mysql表
void clrstr(char *buf){
buf[0] = '\0';
}
int main(int argc, char *argv[]) {
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
MYSQL_FIELD *field;
char query[MAX_QUERY];
int x;
int i = 0;
char *records[] = {
"LOAD DATA INFILE 'test.html' INTO TABLE students"};
mysql_init(&mysql);
mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "mydb");
if (!mysql_real_connect(&mysql, HOSTNAME, USERNAME, PASSWORD,
DATABASE, 0, NULL, 0)) {
error("Could not connect to host.",&mysql);
}
clrstr(query);
/* varchar max*/
strcat(query, "create table students (id int not null auto_increment, fileaa text(65535),primary key(id))");
printf("Creating students table.\n");
/*
Create students table
*/
if(mysql_query(&mysql, query)){
error("Could not create table!",&mysql);
}
clrstr(query);
/*
Insert a records into the students table
*/
printf("Inserting students.\n");
for(x = 0; x < 1; x++){
if(mysql_query(&mysql, records[x])){
printf("Failure to insert: %s\n",records[x]);
error("Could not insert record",&mysql);
}
}
clrstr(query);
/*
Let us look at what we inserted
*/
strcpy(query, "select * from students order by last_name");
if(mysql_query(&mysql, query))
error("failed select 1",&mysql);
/*
Store results from query into res structure.
*/
if (!(res = mysql_store_result(&mysql))){
error("failed store 1",&mysql);
}
/*
print all results
*/
while ((row = mysql_fetch_row(res))) {
for (i=0; i < mysql_num_fields(res); i++){
printf("%s ", row[i]);
}
printf("\n");
}
/*
Drop the students table
*/
strcpy(query, "drop table students");
if(mysql_query(&mysql,query))
error("fail drop 1",&mysql);
/*
Finally close connection to server
*/
mysql_close(&mysql);
printf("All done\n");
return 0;
}
我试图加入这一行
strcat(query, "GRANT FILE ON *.* TO 'james'@'localhost',create table students (id int not null auto_increment, fileaa text(65535),primary key(id))");
但后来我最终得到一个语法错误在该行代替。当我不断收到权限错误时,我不确定如何将此文件插入到数据库中。
'php'与这个有什么关系? – Irvin
你为什么从HTML文件中读取?它不应该是一个文本文件的数据? –
我相信你在这里不使用blob。 – jned29