一直以來,我就想用SQLite來當開發用的資料庫,因為我可以把整個專案連同資料庫一起打包成壓縮檔,這樣作法除了比較好做整個備份,在換不同的工作環境時(在家或公司),也能輕鬆移植運作。

在Kohana2.3.4時,可以在system\libraries\drivers\Database找到Pdosqlite.php來使用。但是在Kohana3.0,Database被轉成為modules後,剩下的drivers似乎只有MySQL和PDO了。 從這樣看來,Ko3的開發人員可能覺得除了常用的MySQL外,其它的資料庫都用PDO去做連結就好了。從PHP官方的PDO文章來看,似乎連MySQL也用PDO連結就好了呀XD

之前在網路上搜尋關鍵字「Kohana3 SQLite」的相關資料,雖然有相關的文章(似乎也是在問Kohana3連結SQLite的問題),但是都沒有成功的解答。其實大家要找的就是Kohana3連結SQLite的DB設定檔啦,不知道為什麼就是沒有一個能動的設定檔。 很幸運的我今天試成功了!喔耶!所以趁現在把這個設定檔公佈出來

/* Kohana database config for SQLite */
return array
(
	'default' => array(
		'type'       => 'pdo',
		'connection' => array(
			/**
			 * The following options are available for PDO:
			 *
			 * string   dsn         Data Source Name
			 * string   username    database username
			 * string   password    database password
			 * boolean  persistent  use persistent connections?
			 */
			'dsn'        => 'sqlite:yourSQLiteDbFilePath.db',
			'username'   => NULL,
			'password'   => NULL,
			'persistent' => FALSE,
		),
		/**
		 * The following extra options are available for PDO:
		 *
		 * string   identifier  set the escaping identifier
		 */
		'table_prefix' => '',
		'charset'      => NULL, // don't set 'utf8',let's be NULL
		'caching'      => FALSE,
		'profiling'    => TRUE,
	),
);
/* application/config/database.php */
1) 確認你的 php_pdo_sqlite.dll 有開啟
2) username、password、charset必需設定為NULL
arrow
arrow
    全站熱搜

    低溫烘培 發表在 痞客邦 留言(0) 人氣()