You have an error in your SQL syntax...
-
게시물 수정 , 삭제는 로그인 필요
#define SOCKET int
#include <string.h>
#include <stdio.h>
#include <mysql.h>
#pragma comment(lib, "libmysql.lib")
#pragma comment(lib, "ws2_32.lib")
#define DB_HOST "localhost"
#define DB_USER "ebinfo2"
#define DB_PASS "ebinfo2"
#define DB_NAME "IMS"
#define SQL_CREATE_TABLE "CREATE TABLE `mysql_api_test` (\
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,\
`num` INT NULL ,\
`string` VARCHAR( 20 ) NULL \
) TYPE = MYISAM ;" //"
#define SQL_INSERT_RECORD "INSERT INTO `mysql_api_test` ( `id` , `num` , `string` ) \
VALUES (\
NULL , '%d', '%s'\
);" //"
#define SQL_SELECT_RECORD "SELECT * FROM `mysql_api_test`"
#define SQL_DROP_TABLE "DROP TABLE `mysql_api_test`"
int main()
{
MYSQL *connection=NULL, conn;
MYSQL_RES *sql_result;
MYSQL_ROW sql_row;
int query_stat;
int i;
char query[255];
mysql_init(&conn);
// DB 연결
connection = mysql_real_connect(&conn, DB_HOST,
DB_USER, DB_PASS,DB_NAME, 3306,(char *)NULL, 0);
if(connection==NULL)
{
fprintf(stderr, "Mysql connection error : %s", mysql_error(&conn));
return 1;
}
// 테이블 생성
query_stat=mysql_query(connection,SQL_CREATE_TABLE);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
// 레코드 삽입
for(i=0;i<5;i++)
{
sprintf(query,SQL_INSERT_RECORD,100+i,"안녕하세요 지돌스타예요~");
query_stat = mysql_query(connection, query);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
}
// 셀렉트
query_stat=mysql_query(connection,SQL_SELECT_RECORD);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
// 결과 출력
sql_result=mysql_store_result(connection);
while((sql_row=mysql_fetch_row(sql_result))!=NULL)
{
printf("%2s %2s %s\n",sql_row[0],sql_row[1],sql_row[2]);
}
mysql_free_result(sql_result);
// 테이블 삭제
query_stat=mysql_query(connection,SQL_DROP_TABLE);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
// DB 연결 닫기
mysql_close(connection);
return 0;
}
컴파일시 오류는 없는데 실행하면 화면에
Mysql query error : You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'TYPE
= MYISAM' at line 1Press any key to continue
라고 뜹니다..조언좀부탁드려요
#define SOCKET int
#include <string.h>
#include <stdio.h>
#include <mysql.h>
#pragma comment(lib, "libmysql.lib")
#pragma comment(lib, "ws2_32.lib")
#define DB_HOST "localhost"
#define DB_USER "ebinfo2"
#define DB_PASS "ebinfo2"
#define DB_NAME "IMS"
#define SQL_CREATE_TABLE "CREATE TABLE `mysql_api_test` (\
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,\
`num` INT NULL ,\
`string` VARCHAR( 20 ) NULL \
) TYPE = MYISAM ;" //"
#define SQL_INSERT_RECORD "INSERT INTO `mysql_api_test` ( `id` , `num` , `string` ) \
VALUES (\
NULL , '%d', '%s'\
);" //"
#define SQL_SELECT_RECORD "SELECT * FROM `mysql_api_test`"
#define SQL_DROP_TABLE "DROP TABLE `mysql_api_test`"
int main()
{
MYSQL *connection=NULL, conn;
MYSQL_RES *sql_result;
MYSQL_ROW sql_row;
int query_stat;
int i;
char query[255];
mysql_init(&conn);
// DB 연결
connection = mysql_real_connect(&conn, DB_HOST,
DB_USER, DB_PASS,DB_NAME, 3306,(char *)NULL, 0);
if(connection==NULL)
{
fprintf(stderr, "Mysql connection error : %s", mysql_error(&conn));
return 1;
}
// 테이블 생성
query_stat=mysql_query(connection,SQL_CREATE_TABLE);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
// 레코드 삽입
for(i=0;i<5;i++)
{
sprintf(query,SQL_INSERT_RECORD,100+i,"안녕하세요 지돌스타예요~");
query_stat = mysql_query(connection, query);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
}
// 셀렉트
query_stat=mysql_query(connection,SQL_SELECT_RECORD);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
// 결과 출력
sql_result=mysql_store_result(connection);
while((sql_row=mysql_fetch_row(sql_result))!=NULL)
{
printf("%2s %2s %s\n",sql_row[0],sql_row[1],sql_row[2]);
}
mysql_free_result(sql_result);
// 테이블 삭제
query_stat=mysql_query(connection,SQL_DROP_TABLE);
if (query_stat != 0)
{
fprintf(stderr, "Mysql query error : %s", mysql_error(&conn));
return 1;
}
// DB 연결 닫기
mysql_close(connection);
return 0;
}
컴파일시 오류는 없는데 실행하면 화면에
Mysql query error : You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'TYPE
= MYISAM' at line 1Press any key to continue
라고 뜹니다..조언좀부탁드려요
#you have divergent branches and need to specify how to reconcile them #you have not concluded your merge (merge_head exists) #you have an error in your sql syntax #you have been locked out of this site #you have my word 뜻 #you have to remove (or rename) that container to be able to reuse that name #you have an error in your sql syntax check the manual that corresponds to your mysql server version #you have new mail in /var/spool/mail/root #you have sent too many messages to the model. please try again later #you have existing submission data. please leave this page and try again