xpress sql 쿼리 질문

Extra Form
PHP PHP 5.3
CMS XpressEngine

모듈을 처음 만들어 보는데요

쿼리를 넣을 string을 디버그 해보면 DEBUG : string('./files/attach/images/65/004/1c645b1360eea53ca0d7e4da318db184.jpg')

로 정상적으로 나오는데

$oDB = DB::getInstance();
            $oDB->use_prepared_statements = 'N';
            $output = executeQuery('sss.sss', $args);
            $oDB->use_prepared_statements = 'Y';

위에 쿼리를 실행하면

[error] => 1064
            [message] => You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '/`files`/`attach`/`images`/65/004/`1c645b1360eea53ca0d7e4da318db184`.`jpg`)' at line 3
            [variables] => Array
                (
                    [_query] => INSERT  INTO `xe_sgame_files`
         (`member_srl`, `file_srl`, `file_name`, `url`)
         VALUES (4, 179, `1522faccf9f52fe078a7df939741e54a`.`jpg`, ./`files`/`attach`/`images`/65/004/`1c645b1360eea53ca0d7e4da318db184`.`jpg`)
                    [_elapsed_time] => 0.00021
                )

 

이런 오류가 나옵니다.

 

어떻게 해결하는건지 모르겠네요.. 도와주세요

  • profile
    해당 아웃풋 쿼리에서 사용되는 url주소가 쿼리 규칙에 어긋나고 있다고 알려주고 있네요. url주소가 어떻게 출력된것인지 점검해보세요.
  • profile ?
    쿼리 실행 전에 디버그로 url을 출력해보면
    DEBUG : string('./files/attach/images/65/004/1c645b1360eea53ca0d7e4da318db184.jpg')
    으로 원하는게 나오는것 같은데
    executequery를 실행하고 output에선
    ./`files`/`attach`/`images`/65/004/`1c645b1360eea53ca0d7e4da318db184`.`jpg`
    처럼 알수없는 따옴표들이 추가되는것 같은데 왜 이러하게 변형되는지 모르겠습니다...
  • ? profile
    $oDB->use_prepared_statements = 'N';

    이거 붙이신 이유가?
  • ? profile
    그리고.. 그 args으로 만든 오브젝트부분 코드랑 debugprint($args) 으로 디버깅찍을때 나온값도 알려주세요
  • profile ?
    function _insertToDB($file_srl, $file_name, $url){
                $logged_info = Context::get('logged_info');
                if(!$logged_info){
                    return false;
                }
        
                $args = new stdClass();
                $args->member_srl = $logged_info->member_srl;
                $args->file_srl = $file_srl;
                $args->file_name = $file_name;
                $args->url = $url;
                $args->regdate = $this->module_config->start_time;
                debugPrint($args);
     
                $oDB = DB::getInstance();
                $oDB->use_prepared_statements = 'N';
                $output = executeQuery('s.insertSImageToDB', $args);
                $oDB->use_prepared_statements = 'Y';
     
                //$output = executeQuery('s.insertSImageToDB', $args);
        
                debugPrint($output);
            }

    args:

     

    DEBUG : stdClass Object
            (
                [member_srl] => 4
                [file_srl] => 180
                [file_name] => 21454E3A582A731B15.png
                [url] => ./files/attach/images/65/004/65ac4cbdb72e8e5929698a7d833fb5ea.png
                [regdate] =>
            )

    output:

     

    DEBUG : BaseObject Object
            (
                [error] => 1064
                [message] => You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '/`files`/`attach`/`images`/65/004/`65ac4cbdb72e8e5929698a7d833fb5ea`.`png`)' at line 3
                [variables] => Array
                    (
                        [_query] => INSERT  INTO `xe_sgame_files`
             (`member_srl`, `file_srl`, `file_name`, `url`)
             VALUES (4, 180, `21454E3A582A731B15`.`png`, ./`files`/`attach`/`images`/65/004/`65ac4cbdb72e8e5929698a7d833fb5ea`.`png`)
                        [_elapsed_time] => 0.00202
                    )
            
                [httpStatusCode] =>
            )

     

    $oDB->use_prepared_statements = 'N'; 은 안하면 디버그 output에서 values 값들이 (?, ?, ?, ?) 로 표시되길래 넣었습니다

  • ? profile
    s.insertSImageToDB 쿼리가 정의된 XML 파일도 보여주셔야 할 것 같습니다. 파일 경로를 값으로 취급해야 하는데 컬럼 이름이나 그 밖의 SQL 문법으로 취급해서 잘못 인코딩하고 있네요.
  • profile ?

    insertSImageToDB 파일이고요:

    <query id="insertSImageToDB" action="insert">
    <tables>
    <table name="s_files" />
    </tables>
    <columns>
    <column name="member_srl" var="member_srl" />
    <column name="file_srl" var="file_srl" />
    <column name="file_name" var="file_name" />
    <column name="url" var="url" />
    <column name="regdate" var="regdate" />
    </columns>
    </query>

    스키마 파일 입니다:

    <table name="s_files">
    <column name="member_srl" type="number" size="11" notnull="notnull" primary_key="primary_key"/>
    <column name="file_srl" type="number" size="11" notnull="notnull" />
    <column name="file_name" type="varchar" size="120" />
    <column name="url" type="varchar" size="120" notnull="notnull" />
    <column name="regdate" notnull="notnull" type="date" index="idx_regdate" />
    </table>

  • ? profile

    primary_key="primary_key"/>에서 /> 앞에 띄어쓰기가 누락된 것 외에는 스키마와 쿼리 모두 특별한 문제는 없어 보입니다. 만약 띄어쓰기가 의심된다면 그 부분 수정해 보시고요...

     

    혹시 한글이나 영어가 아닌 다른 언어를 기본으로 사용하거나, UTF-8이 아닌 서버 환경에서 운영하고 계신가요? 저런 식으로 escape 처리가 잘못 되는 경우는 서버 환경이 XE와 맞지 않아서 그럴 수도 있거든요.

  • profile ?
    아 제가 xampp를 쓰고 있었는데 버전이 오래되었던 탓인지 업데이트를 하니까 잘되네요...

    답변해주신분들 정말 감사합니다!