You cannot see this page without javascript.

test/test.php

<?php
 define('__ZBXE__', true);
 define('__XE__', true);
 require_once $_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php';
 $oContext = &Context::getInstance();
 $oContext->init();
      $args->document_srl = 1608;
      $args->rateval = 1; //1점이상인 사람만 가져옴
      $output = executeQueryArray('widgets.star_rating.getStarRatedList', $args);

 echo print_r($output,true);

$oContext->close();

?>

 


widgets/star_rating/query/getStarList.xml

 

<query id="getDocumentStarRatedList" action="select">
    <tables>
        <table name="document_voted_log" />
    </tables>
    <columns>
        <column name="member_srl" />
        <column name="rateval" />
    </columns>
    <conditions>
        <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" pipe="and" />
        <condition operation="more" column="rateval" var="rateval" filter="number" pipe="and" />
    </conditions>
</query>


 

위와 같이 test.php 파일과 getStarList.xml 이라는 파일을 생성하고 test.php를 실행하면 제대로 배열값이 표시됩니다.

 

 

*풀이하기

 

1. test.php파일에 config.inc.php 를 읽어 들이면

'config/func.inc.php' 파일을 함께 포함하게 되면 아래와 같이 func.in.php에 정의된 다양한 xe의 기본 함수를 사용할 수 있습니다.

 

    function executeQuery($query_id, $args = null) {
        $oDB = &DB::getInstance();
        return $oDB->executeQuery($query_id, $args);
    }


 

2. 단,  $oContext = &Context::getInstance(); 를 선언해 주어야 제대로 작동합니다.

 

*고민

  

xe의 모듈과 위젯의 query를 이용할 수 있다는 점은 좋지만

새로운 db query 문을 실행하기 위해서는 선택을 해야합니다.

특정 모듈의 query 폴더에 쿼리 내용의 xml 파일을 만들어 저장하여 executeQuery() 함수를 사용할 것인지

아니면  $oDB=&DB::getInstance(); 를 선언하 사용할 것인지를.

 

아래의 코드는 위와 비슷한 db값을 출력하는 내용입니다. 다른 점을 찾아보세요.

 

test/test2.php

 

<?php
 define('__ZBXE__', true);
 define('__XE__', true);
 require_once $_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php';
 $oContext = &Context::getInstance();
 $oContext->init();

 $oDB = &DB::getInstance();

 

 //$args->document_srl = 1608;
 //$args->rateval = 1; //1점이상인 사람만 가져옴

$member_srl = 4;

$document_srl = 1608;
$tablename = 'db_document_voted_log';

 // 사용자가 투표한 적이 있는지 검사
 $result = $oDB->_query("select rateval from $tablename where member_srl='$member_srl' && document_srl='$document_srl'");
 $output = $oDB->_fetch($result); //배열 재구성


echo print_r($output,true);

$oContext->close();

?>

엮인글 :
List of Articles
번호 제목 글쓴이 날짜 조회 수sort
149 Network HSRP 구성 file [20] LynX 2015-04-29 803
148 CentOS memchached [1] LynX 2016-04-21 808
147 CentOS Grub UUID change LynX 2018-08-08 810
146 Server 톰켓 설치 file LynX 2014-05-20 812
145 CentOS7 ▒ Doly의 CentOS7 강좌 9 3. CentOS시작, 종료, 둘러보기 -1 file [12] LynX 2014-10-23 812
144 Server 웹 동접자 수 확인 코드 LynX 2016-09-08 831
143 CentOS apm소스 [9] LynX 2015-05-29 835
142 Windows Windows 10 재작 툴 file [21] LynX 2015-08-19 840
141 SoftWare 네트워크 블러그 LynX 2013-09-29 841
140 Xpress Engine XE 애드온 --XE 애드온의 기초 이해 LynX 2014-07-11 842
139 Linux Linux Telnet, SSH 설치 LynX 2014-06-30 843
138 HardWare 라우터 초기화 LynX 2014-03-25 847
137 mms 스트리밍 파일 다운로드 file LynX 2012-12-12 853
136 Linux OpenBSD APM Source Compile [2] LynX 2016-07-04 869
135 CentOS7 ▒ Doly의 CentOS7 강좌22 7. 사용자와 그룹관리 3-관리자 권한 전환 [19] LynX 2015-06-09 887
134 APM Apache 2.4 설치 file LynX 2013-12-30 890
133 Programing make - 05 내부 매크로 LynX 2017-02-22 896
132 CentOS7 ▒ Doly의 CentOS7 강좌17 6. CentOS 네트워크 3-호스트네임 설정 file LynX 2014-10-23 912
» Xpress Engine xe 외부 php 파일에서 db 접근하기 executeQuery() LynX 2014-07-14 919
130 CentOS7 ▒ Doly의 CentOS7 강좌26 10. 디스크관리 5 LVM 5.1 SSM file [9] LynX 2015-06-09 919

XE Login