function cubrid_mysql_fetch_array($result, $result_type = 1) { return cubrid_fetch($result, $result_type); }
public static function fetch($handle = null, $type = 'assoc') { $realtype = self::__queryType($type); return cubrid_fetch($handle, $realtype); }
#!/usr/bin/php <?php $sql = "insert into foo1 values(1,1)"; for ($i = 0; $i < 1; $i++) { $con = @cubrid_connect("test-db-server", 33113, "testdb", "dba", ""); if ($con) { $req = cubrid_query($sql, $con); if ($req) { echo "cubrid_query error"; } while ($row = cubrid_fetch($req)) { echo "to: \$ row [0], b: \$ row [1] \\ n"; } if ($req) { cubrid_close_request($req); } cubrid_disconnect($con); } else { echo "failed cubrid_connect . \\ n "; sleep(1); } }
/** * Fetch the result * @param resource $result * @param int|NULL $arrayIndexEndValue * @return array */ function _fetch($result, $arrayIndexEndValue = NULL) { $output = array(); if (!$this->isConnected() || $this->isError() || !$result) { return array(); } if ($this->use_prepared_statements == 'Y') { } // TODO Improve this piece of code // This code trims values from char type columns $col_types = cubrid_column_types($result); $col_names = cubrid_column_names($result); $max = count($col_types); for ($count = 0; $count < $max; $count++) { if (preg_match("/^char/", $col_types[$count]) > 0) { $char_type_fields[] = $col_names[$count]; } } while ($tmp = cubrid_fetch($result, CUBRID_OBJECT)) { if (is_array($char_type_fields)) { foreach ($char_type_fields as $val) { $tmp->{$val} = rtrim($tmp->{$val}); } } if ($arrayIndexEndValue) { $output[$arrayIndexEndValue--] = $tmp; } else { $output[] = $tmp; } } unset($char_type_fields); if ($result) { cubrid_close_request($result); } if (count($output) == 1) { // If call is made for pagination, always return array if (isset($arrayIndexEndValue)) { return $output; } else { return $output[0]; } } return $output; }
<?php include_once "connect.inc"; header('Content-type: text/html; charset=euc-kr'); //var_dump($connect_url); $conn = cubrid_connect_with_url($connect_url); $sql = "SELECT a from foo"; $result = cubrid_execute($conn, $sql); $pResult = cubrid_fetch($result); echo $pResult[0]; echo "<br/>"; cubrid_close_request($result); cubrid_rollback($conn); cubrid_disconnect($conn);
fclose($fh); printf("%d records readed.\n", $count - 1); $dh = cubrid_connect($db["host"], $db["port"], $db["dbname"], $db["username"], $db["password"]); if ($dh === false) { sprintf("DB Error %d (%d): %s\n", cubrid_error_code(), cubrid_error_code_facility(), cubrid_error_msg()); exit(0); } $result = cubrid_execute($dh, "SELECT count (\"class_name\") AS \"cnt\" " . "FROM \"db_class\" WHERE " . "\"class_name\" = '" . $db["table"] . "';"); if ($result === false) { printf("DB Error %d (%d): %s\n", cubrid_error_code(), cubrid_error_code_facility(), cubrid_error_msg()); cubrid_rollback($dh); cubrid_disconnect($dh); exit(0); } cubrid_commit($dh); $is_exist = cubrid_fetch($result, CUBRID_NUM); if ($is_exist === false) { printf("DB Error %d (%d): %s\n", cubrid_error_code(), cubrid_error_code_facility(), cubrid_error_msg()); cubrid_close_request($result); cubrid_disconnect($dh); exit(0); } cubrid_close_request($result); $is_exist = $is_exist[0] ? true : false; if ($is_exist === true) { $result = cubrid_execute($dh, "DROP TABLE \"" . $db["table"] . "\";"); if ($result === false) { printf("DB Error %d (%d): %s\n", cubrid_error_code(), cubrid_error_code_facility(), cubrid_error_msg()); cubrid_rollback($dh); cubrid_disconnect($dh); exit(0);
/** * @group php-822 */ public function testCubridRollBack1() { if (OUTPUT_FUNCTION_NAME == true) { echo "\r\nRunning: " . __FUNCTION__ . " = "; } $this->sql = "create table test1 (id int)"; cubrid_execute($this->con, $this->sql); $this->sql = "insert into test1 values(2)"; $this->req = cubrid_execute($this->con, $this->sql); cubrid_commit($this->con); $this->sql = "update test1 set id=3 where id=2"; $this->req = cubrid_execute($this->con, $this->sql); $this->sql = "select * from test1"; $this->req = cubrid_execute($this->con, $this->sql); list($id) = cubrid_fetch($this->req); $this->assertEquals(3, $id); $this->sql = "drop test1"; $this->req = cubrid_execute($this->con, $this->sql); cubrid_commit($this->con); $this->req = null; $this->con = null; }
/** * @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다 * * 그닥 좋지는 않은 구조이지만 편리하다.. -_-; **/ function _getNavigationData($table_list, $columns, $left_join, $condition, $output) { require_once _XE_PATH_ . 'classes/page/PageHandler.class.php'; /* // group by 절이 포함된 SELECT 쿼리의 전체 갯수를 구하기 위한 수정 // 정상적인 동작이 확인되면 주석으로 막아둔 부분으로 대체합니다. // $count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition; $total_count = $this->getCountCache($output->tables, $count_condition); if($total_count === false) { $count_query = sprintf('select count(*) as "count" from %s %s %s', implode(', ', $table_list), implode(' ', $left_join), $count_condition); if (count($output->groups)) $count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query); $result = $this->_query($count_query); $count_output = $this->_fetch($result); $total_count = (int)$count_output->count; $this->putCountCache($output->tables, $count_condition, $total_count); } */ // 전체 개수를 구함 $count_query = sprintf("select count(*) as \"count\" from %s %s %s", implode(',', $table_list), implode(' ', $left_join), $condition); $total_count = $this->getCountCache($output->tables, $condition); if ($total_count === false) { $result = $this->_query($count_query); $count_output = $this->_fetch($result); $total_count = (int) $count_output->count; $this->putCountCache($output->tables, $condition, $total_count); } $list_count = $output->list_count['value']; if (!$list_count) { $list_count = 20; } $page_count = $output->page_count['value']; if (!$page_count) { $page_count = 10; } $page = $output->page['value']; if (!$page) { $page = 1; } // 전체 페이지를 구함 if ($total_count) { $total_page = (int) (($total_count - 1) / $list_count) + 1; } else { $total_page = 1; } // 페이지 변수를 체크 if ($page > $total_page) { $page = $total_page; } $start_count = ($page - 1) * $list_count; $query = sprintf("select %s from %s %s %s", $columns, implode(',', $table_list), implode(' ', $left_join), $condition); if (count($output->groups)) { $query .= sprintf(' group by %s', implode(',', $output->groups)); } if ($output->order) { foreach ($output->order as $key => $val) { if ($val[0] != 'count') { if (strpos($val[0], '.')) { $tmpval = explode('.', $val[0]); $tmpval[0] = sprintf('"%s"', $tmpval[0]); $tmpval[1] = sprintf('"%s"', $tmpval[1]); $val[0] = implode('.', $tmpval); } elseif (strpos($val[0], '(')) { $val[0] = $val[0]; } else { $val[0] = sprintf('"%s"', $val[0]); } } $index_list[] = sprintf('%s %s', $val[0], $val[1]); } if (count($index_list)) { $query .= ' order by ' . implode(',', $index_list); } $query = sprintf('%s for orderby_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count); } else { if (count($output->groups)) { $query = sprintf('%s having groupby_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count); } else { if ($condition) { $query = sprintf('%s and inst_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count); } else { $query = sprintf('%s where inst_num() between %d and %d', $query, $start_count + 1, $list_count + $start_count); } } } $result = $this->_query($query); if ($this->isError()) { $buff = new Object(); $buff->total_count = 0; $buff->total_page = 0; $buff->page = 1; $buff->data = array(); $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); return $buff; } $virtual_no = $total_count - ($page - 1) * $list_count; while ($tmp = cubrid_fetch($result, CUBRID_OBJECT)) { $data[$virtual_no--] = $tmp; } $buff = new Object(); $buff->total_count = $total_count; $buff->total_page = $total_page; $buff->page = $page; $buff->data = $data; $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); return $buff; }