Source for file EDB_CUBRID.php
Documentation is available at EDB_CUBRID.php
* Project: EDB_CUBRID :: CUBRID abstraction layer
* File: EDB/EDB_CUBRID.php
* The EDB_CUBRID class is cubrid abstraction layer that used internally
* @subpackage EDB_ABSTRACT
* @author JoungKyun.Kim <http://oops.org>
* @copyright (c) 2018, JoungKyun.Kim
* @link http://pear.oops.org/package/EDB
* CUBRID engine for EDB API
* This class support abstracttion DB layer for CUBRID Engine
* db handler of EDB_CUBRID class
* The number of query parameter
* Default transaction status
private $trstatus = false;
// {{{ (object) EDB_CUBRID::__construct ($host, $user, $pass, $db)
* Instantiates an EDB_CUBRID object and opens an cubrid database
* $db = new EDB_CUBRID ('cubrid://localhost', 'user', 'host', 'database');
* $db = new EDB_CUBRID ('cubrid://localhost:33000', 'user', 'host', 'database');
* $db = new EDB_CUBRID ('cubrid://localhost:33000?autocommit=false', 'user', 'host', 'database');
* If you add prefix 'p~' before host, you can connect with persistent
* $db = new EDB_CUBRID ('cubrid://p~localhost', 'user', 'host', 'database');
* @param string $hostname cubrid host
* @param string $user cubrid user
* @param string $password cubrid password
* @param string $database cubrid database
$argv = is_array ($_argv[0]) ? $_argv[0] : $_argv;;
throw new myException ('CUBRID extension is not loaded on PHP!', E_USER_ERROR);
if ( preg_match ('/\?.*/', $o->host, $matches) ) {
if ( preg_match ('/^([^:]+):(.+)/', $o->host, $matches) ) {
$func = 'cubrid_pconnect_with_url';
$func = 'cubrid_connect_with_url';
$url = sprintf ('CUBRID:%s:%s:::%s', $o->host, $o->db, $o->opt);
$this->db = $func ($url, $o->user, $o->pass);
$this->trstatus = cubrid_get_autocommit ($this->db);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_CUBRID::get_charset (void)
* Get character set of current database
* CUBRID extension don't support this function
* @return string Current character set name on DB
return cubrid_get_charset ($this->db);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (bool) EDB_CUBRID::set_charset ($charset)
* Set character set of current database
* This method is always returned true because CUBRID don't support
* @return bool always return true
* @param string name of character set that supported from database
// {{{ (string) EDB_CUBRID::escape ($string)
* Escape special characters in a string for use in an SQL statement
* @param string The string that is to be escaped.
return cubrid_real_escape_string ($string, $this->db);
// {{{ (int) EDB_CUBRID::query ($query, $param_type, $param1, $param2 ...)
* Performs a query on the database
* @return integer The number of affected rows or false
* @param string $query The query strings
* @param string $type (optional) Bind parameter type. See also
* {@link http://php.net/manual/en/cubridi-stmt.bind-param.php cubridi_stmt::bind_param}.
* @param mixed $param1 (optional) Bind parameter 1
* @param mixed $param2,... (optional) Bind parameter 2 ..
$argv = is_array ($_argv[0]) ? $_argv[0] : $_argv;;
// store query in log variable
if ( $this->pno++ == 0 ) // no bind query
$this->no_bind_query ($sql);
$this->bind_query ($sql, $argv);
if ( preg_match ('/^(update|insert|delete|replace)/i', trim ($sql)) ) {
/* Insert or update, or delete query */
return cubrid_affected_rows ($this->db);
for ( $i= 0; $i< $fno; $i++ ) {
if ( $type == 'blob' || $type == 'clob' )
$this->lob = array ($lob);
return cubrid_num_rows ($this->result);
// {{{ (string) EDB_CUBRID::lastId (void)
* 가장 마지막 입력 row ID를 반환한다.
return qubrid_insert_id ($this->db);
// {{{ (bool) EDB_CUBRID::seek ($offset)
* Move the cursor in the result
* @param Number of units you want to move the cursor.
function seek ($offset) {
// cubrid_move_cursor은 시작점이 0이 아니라 1이라서
// 호환성에 문제가 있어 cubrid_data_seek를 사용한다.
//return cubrid_move_cursor ($this->result, $offset, CUBRID_CURSOR_FIRST);
return cubrid_data_seek ($this->result, $offset);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (object) EDB_CUBRID::fetch (void)
* Fetch a result row as an associative object
* @return stdClass|falseThe object of fetched a result row or false
* @param boolean (optional) 수행후 result를 free 한다. 기본값: false
function fetch ($free = false) {
$r = cubrid_fetch ($this->result, CUBRID_OBJECT | CUBRID_LOB);
foreach ( $this->lob as $keyname ) {
$len = cubrid_lob2_size64 ($r->$keyname);
$r->$keyname = cubrid_lob2_read ($r->$keyname, $len);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (array) EDB_CUBRID::fetch_all ($free = true)
* Fetch all result rows as an associative object
* @return array The fetched object result rows
* @param boolean (optional) free result set after fetch.
while ( ($r = $this->fetch ()) !== false )
// {{{ (bool) EDB_CUBRID::free_result (void)
* Frees stored result memory for the given statement handle
if ( ! $this->free ) return true;
#return cubrid_free_result ($this->result);
return cubrid_close_request ($this->result);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_CUBRID::field_name ($index)
* Return the name of the specified field index
* @param integer The numerical field offset. The field_offset starts
* at 0. If field_offset does not exist, return false
* and an error of level E_WARNING is also issued.
* @see http://php.net/manual/en/function.cubrid-field-name.php cubrid_field_name()
return cubrid_field_name ($this->result, $index);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_CUBRID::field_type ($index)
* Get the type of the specified field in a result
* @param integer The numerical field offset. The field_offset starts
* at 0. If field_offset does not exist, return false
* and an error of level E_WARNING is also issued.
* @see http://php.net/manual/en/function.cubrid-field-type.php cubrid_field_type()
return cubrid_field_type ($this->result, $index);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (int) EDB_CUBRID::num_fields (void)
* Return the number of columns in the result set
* @return integer|falsereturn -1 if SQL sentence is not SELECT.
* @see http://php.net/manual/en/function.cubrid-num-fields.php cubrid_num_fileds()
return cubrid_num_cols ($this->result);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (void) EDB_CUBRID::trstart (void)
if ( $this->trstatus === true )
cubrid_set_autocommit ($this->db, CUBRID_AUTOCOMMIT_FALSE);
// {{{ (void) EDB_CUBRID::trend ($v)
* @param bool false일경우 rollback을 수행한다.
function trend ($v = true) {
cubrid_commit ($this->db);
cubrid_rollback ($this->db);
$mode = ($this->trstatus === true) ? CUBRID_AUTOCOMMIT_TRUE : CUBRID_AUTOCOMMIT_FALSE;
cubrid_set_autocommit ($this->db, $mode);
// {{{ (void) EDB_CUBRID::close (void)
cubrid_disconnect ($this->db);
// {{{ private (int) EDB_CUBRID::no_bind_query ($sql)
* Performs a query on the database
* @return integer The number of affected rows or false
* @param string The query strings
private function no_bind_query ($sql) {
$this->result = cubrid_query ($sql, $this->db);
if ( cubrid_error_code () ) {
throw new myException (cubrid_error_msg (), E_USER_WARNING);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ private (int) EDB_CUBRID::bind_query ($sql, $parameters)
* Performs a bind query on the database
* @return integer The number of affected rows or false
* @param string The query strings
* @param array (optional) Bind parameter type
private function bind_query ($sql, $params) {
if ( $this->pno != count ($params) || $this->check_param ($params) === false ) {
'Number of elements in query doesn\'t match number of bind variables',
$this->result = cubrid_prepare ($this->db, $sql);
for ( $i= 1; $i< $this->pno; $i++ ) {
switch ($params[0][$i- 1]) {
is_object ($params[$i]) ? $params[$i]->data : $params[$i],
is_object ($params[$i]) ? $params[$i]->data : $params[$i],
cubrid_bind ($this->result, $i, $params[$i]);
cubrid_execute ($this->result);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
} catch ( Exception $e ) { }
* vim: set filetype=php noet sw=4 ts=4 fdm=marker:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
|