Extra Form
PHP PHP 7.4
CMS Rhymix 2.1

아래와 같이 시도해봤는데 둘다 안되네요.

컬럼 type를 확인해서 int 일경우 text 로 변경을하려고 합니다.

 

1.show columns

$oDB = DB::getInstance();
$query = $oDB->_query('show columns from documents');
$result = $oDB->_fetch($query);

 

$result 는 null;

 

2. INFORMATION_SCHEMA

$oDB = DB::getInstance();
$table_name = "documents";
$column_name = "document_srl";
$args = array($table_name, $column_name);
$stmt = $oDB->query('SELECT column_name, data_type FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = ? AND column_name =?' , $args);
$result = $stmt->fetchAll();

 

 

서버 메세지 : SQLSTATE[42000]: Syntax error or access violation: 1064 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 '.COLUMNS WHERE table_name = ? AND column_name =?' at line 1

 

 

  • profile

    테이블명에서 rx_ xe_ 등 접두사가 빠진 것 같습니다.

    1. _query() + _fetch() 방식은 접두사를 자동으로 붙여 주지 않습니다. XE 시절부터 비공식적으로 통용된, 날것 그대로의 쿼리가 실행됩니다.

    2. query() 메소드는 접두사를 자동으로 붙여 주지만, FROM이나 JOIN에 사용된 테이블명에 한합니다. $args로 넘긴 문자열까지 일일이 고쳐 주지는 않습니다.

     

    그러나 단지 컬럼 타입을 알고 싶으신 것 뿐이라면 SQL 쿼리를 작성할 필요도 없습니다.

        $oDB->getColumnInfo('rx_를 제외한 테이블명', '컬럼명');

    하시면 예쁘게 오브젝트로 나옵니다.

  • profile profile
    getColumnInfo 가 있었군요.
    감사합니다.