Created
April 29, 2014 23:41
-
-
Save chocomelonchan/3881fed1a46b380b6c4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LilyLite { | |
private static $lily_lite = null; | |
private $link = null; | |
/** | |
* DBの初期化 | |
* | |
* @param string $db_path DBファイルのpath | |
*/ | |
private function __construct($db_path) | |
{ | |
$this->link = sqlite_open($db_path, 0666, $sqliteerror); | |
if (!empty($sqliteerror)) { | |
throw new Exception($sqliteerror); | |
} | |
} | |
/** | |
* シングルトンで初期化 | |
* | |
* @param string $db_path DBファイルのpath | |
*/ | |
public static function getInstance($db_path) | |
{ | |
if ($lily_lite === null) { | |
$lily_lite = new LilyLite($db_path); | |
} | |
return $lily_lite; | |
} | |
/** | |
* クエリの結果を連想配列で返す | |
* | |
* @param string $query クエリ | |
* @return array クエリの結果の連想配列 | |
*/ | |
public function query($query) | |
{ | |
$result = sqlite_query($this->link, $query, SQLITE_BOTH, $sqliteerror); | |
if (empty($result)) { | |
throw new Exception($sqliteerror); | |
} | |
$convert_result = array(); | |
while ($rows = sqlite_fetch_array($result, SQLITE_ASSOC)) { | |
$convert_result[] = $rows; | |
} | |
return $convert_result; | |
} | |
/** | |
* DBのclose | |
*/ | |
public function close() | |
{ | |
sqlite_close($this->link); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment