cubrid_fetch_object

(PECL CUBRID >= 8.3.0)

cubrid_fetch_object — 다음 행을 가져와서 객체로 반환


설명

cubrid_fetch_object(
    resource $result,
    string $class_name = ?,
    array $params = ?,
    int $type = ?
): object
                

이 함수는 결과 집합의 열 이름을 속성으로 가진 개체를 반환합니다. 이러한 속성의 값은 결과의 현재 행에서 추출됩니다.


매개변수

result
cubrid_execute()를 호출한 result
class_name
인스턴스화할 클래스의 이름입니다. 지정하지 않으면 stdClass(stdClass는 다른 유형을 객체로 캐스팅할 때 사용되는 PHP의 일반 빈 클래스임) 객체가 반환됩니다.
params
class_name 객체의 생성자에 전달할 매개변수의 선택적 배열입니다.
type
Type은 CUBRID_LOB만 가능하며, 이 매개변수는 lob 객체를 조작해야 하는 경우에만 사용됩니다.

반환 값

프로세스가 성공한 경우 개체입니다.

행이 더 이상 없으면 false입니다. NULL, 프로세스가 성공하지 못한 경우.


Examples

예제 #1 cubrid_fetch_object() 예제

                  
<?php
$conn = cubrid_connect("localhost", 33000, "demodb");
$res = cubrid_execute($conn, "SELECT * FROM code");

var_dump(cubrid_fetch_object($res));

// if you want to operate LOB object, you can use cubrid_fetch_object($res, CUBRID_LOB)

class demodb_code {
    public $s_name = null;
    public $f_name = null;

    public function toString() {
        var_dump($this);
    }
}

var_dump(cubrid_fetch_object($res, "demodb_code"));

// if you want to operate LOB object, you can use cubrid_fetch_object($res, "demodb_code", CUBRID_LOB)

class demodb_code_construct extends demodb_code {
    public function __construct($s, $f) {
        $this->s_name = $s;
        $this->f_name = $f;
    }
}

var_dump(cubrid_fetch_object($res, 'demodb_code_construct', array('s_name', 'f_name')));

// if you want to operate LOB object, you can use cubrid_fetch_object($res, 'demodb_code_construct', array('s_name', 'f_name'), CUBRID_LOB)


var_dump(cubrid_fetch_object($res));

cubrid_close_request($res);
cubrid_disconnect($conn);
?>
                  
                

위의 예는 다음을 출력합니다.

object(stdClass)#1 (2) {
  ["s_name"]=>
  string(1) "X"
  ["f_name"]=>
  string(5) "Mixed"
}
object(demodb_code)#1 (2) {
  ["s_name"]=>
  string(1) "W"
  ["f_name"]=>
  string(5) "Woman"
}
object(demodb_code_construct)#1 (2) {
  ["s_name"]=>
  string(6) "s_name"
  ["f_name"]=>
  string(6) "f_name"
}
object(stdClass)#1 (2) {
  ["s_name"]=>
  string(1) "B"
  ["f_name"]=>
  string(6) "Bronze"
}
                

기타