| 제목 | DB 생성하고 확인하기 | ||
|---|---|---|---|
| 글쓴이 | 구준호 | 작성시각 | 2010/06/18 13:02:02 |
|
|
|||
function Test()
{
parent::Controller();
$this->load->dbutil();
$this->load->dbforge();
}
function index()
{
echo "<a href='http://127.0.0.1/index.php/test/create'>create database</a><br/>";
echo "<a href='http://127.0.0.1/index.php/test/drop'>drop database</a><br/>";
echo "<a href='http://127.0.0.1/index.php/test/create_and_drop'>create and drop database</a><br/>";
echo "<a href='http://127.0.0.1/index.php/test/check'>check</a><br/>";
}
function create()
{
$this->dbforge->create_database('octo_test');
$this->check();
}
function drop()
{
$this->dbforge->drop_database('octo_test');
$this->check();
}
function create_and_drop()
{
$this->dbforge->create_database('octo_test');
print_r($this->dbutil->list_databases());
$this->dbforge->drop_database('octo_test');
print_r($this->dbutil->list_databases());
}
function check()
{
print_r($this->dbutil->list_databases());
}
위처럼 Controller를 만들었습니다.database 를 create 하거나 drop은 잘 됩니다. 그런데 create_and_drop 에서 list_databases를 해보면 결과가 다음처럼 나옵니다. Array ( [0] => information_schema [1] => mysql [2] => octo [3] => octo_test [4] => phpmyadmin ) Array ( [0] => information_schema [1] => mysql [2] => octo [3] => octo_test [4] => phpmyadmin ) octo_tst 라는 database가 여전히 존재하는 것처럼 나옵니다. 실제로는 지워졌고요. 왜 이럴까요? |
|||
| 다음글 | 링크를 누르면 계속 디폴트페이지가 뜹니다. (2) | ||
| 이전글 | 트위터 OAuth 연동시 콜백 함수를 위한 초보의 질문... (11) | ||
|
구준호
/
2010/06/18 13:05:07 /
추천
0
|
|
구준호
/
2010/06/18 13:13:28 /
추천
0
자답입니다. CI의 CI_DB_utility의 list_databases()를 보니 답이 나오는 군요. 캐시 $this->data_cache['db_names'] 가 이미 set 됐으면 캐시된 값을 리턴합니다. 감사합니다. ^^
/**
* List databases
*
* @access public
* @return bool
*/
function list_databases()
{
// Is there a cached result?
if (isset($this->data_cache['db_names']))
{
return $this->data_cache['db_names'];
}
$query = $this->db->query($this->_list_databases());
$dbs = array();
if ($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$dbs[] = current($row);
}
}
$this->data_cache['db_names'] = $dbs;
return $this->data_cache['db_names'];
} |
function create_and_drop() { $this->load->dbutil(); $this->dbforge->create_database('octo_test'); print_r($this->dbutil->list_databases()); $this->load->dbutil(); $this->dbforge->drop_database('octo_test'); print_r($this->dbutil->list_databases()); }