Posted
Filed under 프로그래밍/PHP

* config/database.php 아래 추가

$db['pdo']['hostname'] = 'mysql:host=localhost;dbname=codeigniter';
$db['pdo']['username'] = 'codeigniter';
$db['pdo']['password'] = 'codeigniter';
$db['pdo']['database'] = 'codeigniter';
$db['pdo']['dbdriver'] = 'pdo';


* 사용하는 방법 (CI 그대로 사용)

//load the pdo db config
$this->pdo = $this->load->database('pdo', true);

//using the pdo config
$stmt = $this->pdo->query("SELECT * FROM users"); 
var_dump($stmt->result());

//using the pdo config with active record
$stmt = $this->pdo->get("users"); 
var_dump($stmt->result());


예제: http://codeigniter-kr.org/user_guide_2.1.0/database/examples.html

출처: http://codebyjeff.com/blog/2013/03/codeigniter-with-pdo

2013/10/15 18:36 2013/10/15 18:36