/** * コンストラクタ */ function __construct() { if (self::isConnect()) { $this->db = self::$connInst; UtilLog::writeLog("PDOインスタンスの再利用: " . print_r(self::$connInst, true), 'DEBUG'); return; } $initDb = false; if (file_exists(DB_FILEPATH)) { if (filesize(DB_FILEPATH) == 0) { $initDb = true; } } else { $initDb = true; } try { $this->db = new PDO('sqlite:' . DB_FILEPATH); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if ($initDb) { // DB初期スクリプト $sql = <<<SQL_TEXT DROP TABLE IF EXISTS `wol_setting`; CREATE TABLE `wol_setting` ( `sid` INTEGER PRIMARY KEY AUTOINCREMENT, `item_name` VARCHAR NOT NULL, `item_value` TEXT NOT NULL ); DROP TABLE IF EXISTS `wol_user`; CREATE TABLE `wol_user` ( `sid` INTEGER PRIMARY KEY AUTOINCREMENT, `user_name` VARCHAR NOT NULL, `user_pass` VARCHAR NOT NULL ); DROP TABLE IF EXISTS `wol_device`; CREATE TABLE `wol_device` ( `sid` INTEGER PRIMARY KEY AUTOINCREMENT, `mac_addr` VARCHAR NOT NULL, `device_name` VARCHAR NOT NULL ); DROP TABLE IF EXISTS `wol_vendor`; CREATE TABLE `wol_vendor` ( `sid` INTEGER PRIMARY KEY AUTOINCREMENT, `mac_header` VARCHAR NOT NULL, `vendor_name` VARCHAR NOT NULL ); SQL_TEXT; $this->db->exec($sql); // 暗号化キー生成 $sql = "INSERT INTO wol_setting ("; $sql .= "item_name, item_value"; $sql .= ") VALUES ("; $sql .= "?, ?"; $sql .= ")"; $stmt = $this->db->prepare($sql); $stmt->bindValue(1, 'CRYPT_KEY'); $stmt->bindValue(2, UtilString::getRandomString(32)); $stmt->execute(); $stmt->closeCursor(); // ベンダー情報更新 self::updateVendorInfo(); } } catch (PDOException $e) { UtilLog::writeLog($e->getMessage()); } }