You have an error in your SQL syntax...

You have an error in your SQL syntax...

작성일 2012.02.09댓글 1건
    게시물 수정 , 삭제는 로그인 필요

 #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

profile_image 익명 작성일 -

#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 ;" //"

여기에 선언된 쿼리를 이용해서 테이블을 생성하려고 할 때 오류가 발생합니다.

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 1P

저 오류 메세지에 DBMS 에서 에러가 발생했고, SQL 문법 오류라고 표시가 됩니다.

일단 쿼리 그 자체로는 문제가 없어 보입니다. mysql 버젼이 낮아서 그런게 아닐까 싶기도 합니다. 아래 쿼리를 mysql 클라이언트에서 직접 실행해 보세요.TYPE = MYISAM ; 을 지워서도 해보시구요.

CREATE
TABLE `mysql_api_test` (
    `id`
INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
   
`num` INT NULL ,
    `string`
VARCHAR( 20 ) NULL
) TYPE = MYISAM ;

You have an error in your SQL syntax...

... return 0; } 컴파일시 오류는 없는데 실행하면 화면에 Mysql query error : You have an error in your SQL syntax; check the manual that corresponds...

You have an error in your SQL...

... 나모 작업하고 작업 파일을 계정으로 업로드한 뒤 게시판을 클릭하니 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server...

You have an error in your SQL syntax...

SQL 질의 SELECT * FROM member WHERE 1 ORDER BY DESC LIMIT 0 , 1 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for...

You have an error in your SQL...

... Message 회원 데이타 입력시 에러가 발생했습니다 You have an error in your SQL syntax near '.'1110688411')' at line 1 초보자라 어디서 어떻게 잘못됏는지 모르겠습니다....

You have an error in your SQL syntax...

... 에러문 오류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 'where no='' and...

You have an error in your SQL syntax;

... 하니까 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 '-1, 1' at line 1 이렇게 뜨더라구요. 그래서...

You have an error in your SQL...

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 '' at line 1 이런 에러가 뜹니다. sql문...

You have an error in your SQL...

... 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 ');/**************'' at line 1 오류나는...