diff -urNbwB foltia.r91/install/mktable.sqlite.txt foltia/install/mktable.sqlite.txt
--- foltia.r91/install/mktable.sqlite.txt	1970-01-01 09:00:00.000000000 +0900
+++ foltia/install/mktable.sqlite.txt	2009-06-09 00:04:20.000000000 +0900
@@ -0,0 +1,279 @@
+
+drop table  foltia_program ;
+
+create table foltia_program (
+tid integer PRIMARY KEY, 
+title text ,
+startweektype text,
+starttime text,
+lengthmin integer,
+firstlight text,
+officialuri text , 
+aspect integer , 
+psp integer , 
+transfer text,
+PSPdirname text 
+);
+create unique index foltia_program_tid_index on foltia_program (tid);
+
+-- REVOKE ALL on "foltia_program" from PUBLIC;
+-- GRANT UPDATE,SELECT,INSERT on "foltia_program" to "foltia";
+
+drop table  foltia_subtitle ;
+
+create table foltia_subtitle (
+pid integer  PRIMARY KEY,
+tid integer, 
+stationid integer,
+countno integer,
+subtitle text,
+startdatetime integer,
+enddatetime integer,
+startoffset integer,
+lengthmin integer,
+m2pfilename text ,
+PSPfilename text ,
+epgaddedby integer , 
+lastupdate timestamp,
+filestatus integer
+);
+create unique index foltia_subtitle_pid_index on foltia_subtitle (pid);
+create  index foltia_subtitle_tid_index on foltia_subtitle (tid);
+create  index foltia_subtitle_stationid_index on foltia_subtitle (stationid);
+create  index foltia_subtitle_enddatetime_index on foltia_subtitle (enddatetime);
+create  index foltia_subtitle_startdatetime_index on foltia_subtitle (startdatetime);
+
+-- REVOKE ALL on "foltia_subtitle" from PUBLIC;
+-- GRANT UPDATE,SELECT,INSERT on "foltia_subtitle" to "foltia";
+
+drop table foltia_tvrecord;
+create table foltia_tvrecord (
+tid integer  ,
+stationid integer,
+bitrate integer ,
+digital integer
+);
+create  index foltia_tvrecord_tid_index on foltia_tvrecord (tid);
+
+-- REVOKE ALL on "foltia_tvrecord" from PUBLIC;
+-- GRANT ALL on "foltia_tvrecord" to "foltia";
+
+
+drop table foltia_epg;
+create table foltia_epg (
+epgid integer   PRIMARY KEY,
+startdatetime integer,
+enddatetime integer,
+lengthmin integer ,
+ontvchannel text,
+epgtitle text,
+epgdesc text,
+epgcategory text 
+);
+create  index foltia_epg_startdatetime_index on foltia_epg (startdatetime);
+create  index foltia_epg_enddatetime_index on foltia_epg (enddatetime);
+create  index foltia_epg_ontvchannel_index on foltia_epg (ontvchannel);
+
+-- REVOKE ALL on "foltia_epg" from PUBLIC;
+-- GRANT ALL on "foltia_epg" to "foltia";
+
+drop table foltia_m2pfiles;
+create table foltia_m2pfiles (
+m2pfilename text 
+);
+-- REVOKE ALL on "foltia_m2pfiles" from PUBLIC;
+-- GRANT ALL on "foltia_m2pfiles" to "foltia";
+
+drop table foltia_mp4files;
+create table foltia_mp4files (
+tid integer,
+mp4filename text 
+);
+-- REVOKE ALL on "foltia_mp4files" from PUBLIC;
+-- GRANT ALL on "foltia_mp4files" to "foltia";
+
+drop table foltia_station;
+CREATE TABLE foltia_station (
+    stationid integer  PRIMARY KEY,
+    stationname text,
+    stationrecch integer,
+    stationcallsign text,
+    stationuri text,
+    tunertype text,
+    tunerch text,
+    device text,
+    ontvcode text,
+	digitalch integer,
+	digitalstationband integer
+);
+--    ADD CONSTRAINT foltia_station_pkey PRIMARY KEY (stationid);
+-- REVOKE ALL on "foltia_station" from PUBLIC;
+-- GRANT ALL on "foltia_station" to "foltia";
+
+--
+-- PostgreSQL database dump
+--
+
+-- SET client_encoding = 'EUC_JP';
+-- SET check_function_bodies = false;
+
+-- SET SESSION AUTHORIZATION 'foltia';
+
+-- SET search_path = public, pg_catalog;
+
+--
+-- TOC entry 3 (OID 17158)
+-- Name: foltia_station; Type: TABLE; Schema: public; Owner: foltia
+--
+
+--
+-- TOC entry 4 (OID 17158)
+-- Name: foltia_station; Type: ACL; Schema: public; Owner: foltia
+--
+
+
+-- SET SESSION AUTHORIZATION 'foltia';
+
+--
+-- Data for TOC entry 6 (OID 17158)
+-- Name: foltia_station; Type: TABLE DATA; Schema: public; Owner: foltia
+--
+INSERT INTO foltia_program VALUES (0, 'EPG録画', '', '', NULL, '', '', 3, 1, '', '');
+INSERT INTO foltia_tvrecord VALUES (0,0,5,1);
+
+
+
+INSERT INTO foltia_station VALUES (0, '[全局]', 0, '', '', '', '', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (1, 'NHK総合', 1, 'NHK', '', NULL, NULL, NULL, '0031.ontvjapan.com',27,0);
+INSERT INTO foltia_station VALUES (3, 'NHK教育', 3, 'ETV', '', NULL, NULL, NULL, '0041.ontvjapan.com',26,0);
+INSERT INTO foltia_station VALUES (4, '日本テレビ', 4, 'NTV', '', NULL, NULL, NULL, '0004.ontvjapan.com',25,0);
+INSERT INTO foltia_station VALUES (6, 'TBS', 6, 'TBS', '', NULL, NULL, NULL, '0005.ontvjapan.com',22,0);
+INSERT INTO foltia_station VALUES (8, 'フジテレビ', 8, 'CX', '', NULL, NULL, NULL, '0006.ontvjapan.com',21,0);
+INSERT INTO foltia_station VALUES (10, 'テレビ朝日', 10, 'EX', '', NULL, NULL, NULL, '0007.ontvjapan.com',24,0);
+INSERT INTO foltia_station VALUES (12, 'テレビ東京', 12, 'TX', '', NULL, NULL, NULL, '0008.ontvjapan.com',23,0);
+INSERT INTO foltia_station VALUES (42, 'tvk', 42, 'TVK', '', '', '', '', '0009.ontvjapan.com',18,0);
+INSERT INTO foltia_station VALUES (14, 'TOKYO MX', 14, 'MX', '', '', '', '', '0016.ontvjapan.com',20,0);
+INSERT INTO foltia_station VALUES (46, 'チバテレビ', -10, 'CTC', '', NULL, NULL, NULL, NULL,30,0);
+INSERT INTO foltia_station VALUES (38, 'テレ玉', -10, 'TVS', '', NULL, NULL, NULL, NULL,32,0);
+INSERT INTO foltia_station VALUES (418, '放送大学', -10, 'UAIR', '', NULL, NULL, NULL, '0013.ontvjapan.com',28,0);
+INSERT INTO foltia_station VALUES (101, 'NHK-BS1', 0, 'BS7', '', '', '101', '', '3001.ontvjapan.com',101,1);
+INSERT INTO foltia_station VALUES (102, 'NHK-BS2', 0, 'BS11', '', '', '102', '', '3002.ontvjapan.com',102,1);
+INSERT INTO foltia_station VALUES (103, 'NHK-BShi', 0, '', '', '', '103', '', '3003.ontvjapan.com',103,1);
+INSERT INTO foltia_station VALUES (409, 'BS日テレ', 0, '', '', '', '141', '', '3004.ontvjapan.com',141,1);
+INSERT INTO foltia_station VALUES (384, 'BS朝日', 0, '', '', '', '151', '', '3005.ontvjapan.com',151,1);
+INSERT INTO foltia_station VALUES (161, 'BS-i', 0, '', '', '', '161', '', '3006.ontvjapan.com',161,1);
+INSERT INTO foltia_station VALUES (389, 'BS Japan', 0, '', '', '', '171', '','3007.ontvjapan.com',171,1);
+INSERT INTO foltia_station VALUES (381, 'BSフジ', 0, '', '', '', '181', '', '3008.ontvjapan.com',181,1);
+INSERT INTO foltia_station VALUES (191, 'WOWOW', 0, 'BS5', '', '', '191', '', '3009.ontvjapan.com',191,1);
+INSERT INTO foltia_station VALUES (420, 'WOWOW2', 0, '', '', '', '192', '', '3010.ontvjapan.com',192,1);
+INSERT INTO foltia_station VALUES (421, 'WOWOW3', 0, '', '', '', '193', '', '3011.ontvjapan.com',193,1);
+INSERT INTO foltia_station VALUES (468, 'BS11デジタル', 0, '', '', '', '211', '', '',211,1);
+INSERT INTO foltia_station VALUES (408, 'ファミリー劇場', 0, '', '', '', '751', '', '1015.ontvjapan.com',NULL,NULL);
+INSERT INTO foltia_station VALUES (397, 'カートゥーンネットワーク', 0, '', '', '', '780', '', '1046.ontvjapan.com',NULL,NULL);
+INSERT INTO foltia_station VALUES (263, 'アニマックス', 0, '', '', '', '782', '', '1047.ontvjapan.com',NULL,NULL);
+INSERT INTO foltia_station VALUES (261, 'キッズステーション', 0, '', '', 'c', '781', '', '1045.ontvjapan.com',NULL,NULL);
+INSERT INTO foltia_station VALUES (449, 'ディスカバリーチャンネル', 0, '', '', '', '796', '', '1062.ontvjapan.com',NULL,NULL);
+INSERT INTO foltia_station VALUES (448, 'MONDO21', 0, '', '', '', '722', '', '1049.ontvjapan.com',NULL,NULL);
+INSERT INTO foltia_station VALUES (401, 'チャンネルNECO', 0, '', '', '', '750', '', '1008.ontvjapan.com',NULL,NULL);
+INSERT INTO foltia_station VALUES (455, '330ch WOWOW', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (480, 'TBSラジオ(954)', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (477, '北海道文化放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (463, 'gooアニメ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (461, '@nifty', -10, '', '', '', '', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (466, 'NHKラジオ第一', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (474, '日テレプラス', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (476, 'ニコニコアニメチャンネル', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (451, 'RKB毎日放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (452, '北海道放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (454, 'テレビ和歌山', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (456, '静岡放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (457, 'i-revo', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (459, '東北放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (464, 'テレビ山口', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (478, '札幌テレビ放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (395, 'カミングスーンTV', -10, '', '', '', '', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (443, 'スーパーチャンネル', -10, '', '', '', '', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (385, 'TBSチャンネル', 0, '', '', '', '765', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (462, '瀬戸内海放送', -10, '', '', '', '', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (473, 'フジCSHD', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (475, 'スカパー181ch', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (479, '北海道テレビ放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (450, 'NHK教育3', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (453, 'バンダイチャンネルキッズ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (458, '日テレプラス＆サイエンス', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (460, 'ビクトリーチャンネル', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (472, 'ytv', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (422, '東海テレビ', -10, '', '', '', '', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (423, 'ShowTime', -10, '', '', '', '', '', '',NULL,NULL);
+INSERT INTO foltia_station VALUES (424, 'メ〜テレ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (425, '三重テレビ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (426, '中京テレビ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (293, 'AT-X', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (295, 'フジ721', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (380, 'スカパー180ch', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (427, '岐阜放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (428, 'テレビ新広島', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (383, 'サンテレビ', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (429, 'CBCテレビ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (386, 'テレ朝チャンネル', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (390, 'サンテレビジョン', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (392, 'スカパー183ch', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (394, 'スカパー160ch', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (396, 'KBS京都', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (398, 'テレビ大阪', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (399, 'ABCテレビ', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (400, 'なし', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (402, '関西テレビ', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (406, 'MBS毎日放送', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (407, 'animate.tv', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (410, 'テレビ愛知', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (411, 'インターネット', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (413, 'よみうりテレビ', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (414, 'LFX488', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (415, 'LFX', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (416, 'LFX BB', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (419, 'GyaO', -10, '', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (417, 'とちぎテレビ', -10, 'TTV', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (412, '群馬テレビ', -10, 'GTV', '', NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (430, '奈良テレビ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (431, 'TVQ九州放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (432, 'テレビ北海道', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (433, 'BIGLOBEストリーム', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (434, 'テレビせとうち', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (435, '中国放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (436, '文化放送(1134)', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (437, '広島ホームテレビ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (438, '広島テレビ', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (439, '岡山放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (440, '山陽放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (441, 'びわ湖放送', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (442, 'NHK-FM', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (444, 'バンダイチャンネル', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (445, 'フレッツ・スクウェア（NTT東日本）', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (446, 'フジ739', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+INSERT INTO foltia_station VALUES (447, 'Yahoo!動画', -10, NULL, NULL, NULL, NULL, NULL, NULL,NULL,NULL);
+
+
+
+
+--
+-- TOC entry 5 (OID 17163)
+-- Name: foltia_station_pkey; Type: CONSTRAINT; Schema: public; Owner: foltia
+--
+
+-- ALTER TABLE ONLY foltia_station
+--     ADD CONSTRAINT foltia_station_pkey PRIMARY KEY (stationid);
+
+drop table foltia_envpolicy;
+CREATE TABLE foltia_envpolicy (
+memberid integer  PRIMARY KEY,
+userclass integer,
+name text,
+passwd1 text ,
+adddate timestamp,
+remotehost text
+);
+-- REVOKE ALL on "foltia_envpolicy" from PUBLIC;
+-- GRANT ALL on "foltia_envpolicy" to "foltia";
+create  index foltia_envpolicy_index on foltia_envpolicy (name);
+insert into foltia_envpolicy  values ( '0','0','foltia','foltiapasswd',datetime('now'),'');
diff -urNbwB foltia.r91/install/perl/addatq.pl foltia/install/perl/addatq.pl
--- foltia.r91/install/perl/addatq.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/addatq.pl	2009-06-06 18:54:00.000000000 +0900
@@ -15,12 +15,13 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 use Schedule::At;
 use Time::Local;
 
 $path = $0;
 $path =~ s/addatq.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -37,85 +38,79 @@
 }
 
 #DB検索(TIDとStationIDからPIDへ)
- $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
 if ($station == 0){
-	$DBQuery =  "SELECT count(*) FROM  foltia_tvrecord WHERE tid = '$tid'  ";
+    $sth = $dbh->prepare($stmt{'addatq.1'});
+    $sth->execute($tid);
 }else{
-	$DBQuery =  "SELECT count(*) FROM  foltia_tvrecord WHERE tid = '$tid' AND stationid  = '$station' ";
+    $sth = $dbh->prepare($stmt{'addatq.2'});
+    $sth->execute($tid, $station);
 }
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
  @titlecount = $sth->fetchrow_array;
 #件数数える
 
 #2以上だったら
 if ($titlecount[0]  >= 2){
-	#全曲取りが含まれているか調べる
-	$DBQuery =  "SELECT count(*) FROM  foltia_tvrecord WHERE tid = '$tid'  AND  stationid  ='0' ";
-	$kth = $dbh->prepare($DBQuery);
-	$kth->execute();
+    #全局録りが含まれているか調べる
+    $kth = $dbh->prepare($stmt{'addatq.3'});
+    $kth->execute($tid);
  	@reservecounts = $kth->fetchrow_array;
 
 	if($reservecounts[0] >= 1 ){#含まれていたら
 		if($tid == 0){
 		#今回の引き数がSID 0だったら
-		#全局取りだけ予約
-#		&writelog("addatq  DEBUG; ALL STATION RESERVE. TID=$tid SID=$station $titlecount[0] match:$DBQuery");
+	    #全局録りだけ予約
+#		&writelog("addatq  DEBUG; ALL STATION RESERVE. TID=$tid SID=$station $titlecount[0] match:$stmt{'addatq.3'}");
 		&addcue;
 		}else{
 		#ほかの全局録画addatqが予約入れてくれるからなにもしない
-#		&writelog("addatq  DEBUG; SKIP OPERSTION. TID=$tid SID=$station $titlecount[0] match:$DBQuery");
+#		&writelog("addatq  DEBUG; SKIP OPERSTION. TID=$tid SID=$station $titlecount[0] match:$stmt{'addatq.3'}");
 		exit;
   		}#end if ふくまれていたら
 	}#endif 2つ以上	
 }elsif($titlecount[0]  == 1){
 		&addcue;
 }else{
-&writelog("addatq  error; reserve impossible . TID=$tid SID=$station $titlecount[0] match:$DBQuery");
+    &writelog("addatq  error; reserve impossible . TID=$tid SID=$station $titlecount[0] match:$stmt{'addatq.3'}");
 }
 
 #旧処理
 # if ($titlecount[0]  == 1 ){
 # 	& addcue;
 # }else{
-#&writelog("addatq  error record TID=$tid SID=$station $titlecount[0] match:$DBQuery");
+#&writelog("addatq  error record TID=$tid SID=$station $titlecount[0] match:$stmt{'addatq.3'}");
 #}
 
 sub addcue{
 
 if ($station == 0){
-	$DBQuery =  "SELECT * FROM  foltia_tvrecord WHERE tid = '$tid'  ";
+	$sth = $dbh->prepare($stmt{'addatq.addcue.1'});
+	$sth->execute($tid);
 }else{
-	$DBQuery =  "SELECT * FROM  foltia_tvrecord WHERE tid = '$tid' AND stationid  = '$station' ";
+	$sth = $dbh->prepare($stmt{'addatq.addcue.2'});
+	$sth->execute($tid, $station);
 }
- $sth = $dbh->prepare($DBQuery);
-$sth->execute();
  @titlecount= $sth->fetchrow_array;
 $bitrate = $titlecount[2];#ビットレート取得
 
 #PID抽出
-$now = &epoch2foldate(`date +%s`);
-$twodaysafter = &epoch2foldate(`date +%s` + (60 * 60 * 24 * 2));
+    $now = &epoch2foldate(time());
+    $twodaysafter = &epoch2foldate(time() + (60 * 60 * 24 * 2));
 #キュー入れは直近2日後まで
 if ($station == 0 ){
-	$DBQuery =  "
-SELECT * from foltia_subtitle WHERE tid = '$tid'  AND startdatetime >  '$now'  AND startdatetime < '$twodaysafter' ";
+	$sth = $dbh->prepare($stmt{'addatq.addcue.3'});
+	$sth->execute($tid, $now, $twodaysafter);
 }else{
-	$DBQuery =  "
-SELECT * from foltia_subtitle WHERE tid = '$tid' AND stationid  = '$station'  AND startdatetime >  '$now'  AND startdatetime < '$twodaysafter' ";
 #stationIDからrecch
-$getrecchquery="SELECT stationid , stationrecch  FROM foltia_station where stationid  = '$station' ";
- $stationh = $dbh->prepare($getrecchquery);
-	$stationh->execute();
+	$stationh = $dbh->prepare($stmt{'addatq.addcue.4'});
+	$stationh->execute($station);
 @stationl =  $stationh->fetchrow_array;
 $recch = $stationl[1];
-}
 
- $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+	$sth = $dbh->prepare($stmt{'addatq.addcue.5'});
+	$sth->execute($tid, $station, $now, $twodaysafter);
+    }
  
 while (($pid ,
 $tid ,
@@ -130,9 +125,8 @@
 
 if ($station == 0 ){
 #stationIDからrecch
-$getrecchquery="SELECT stationid , stationrecch  FROM foltia_station where stationid  = '$stationid' ";
- $stationh = $dbh->prepare($getrecchquery);
-	$stationh->execute();
+	    $stationh = $dbh->prepare($stmt{'addatq.addcue.6'});
+	    $stationh->execute($stationid);
 @stationl =  $stationh->fetchrow_array;
 $recch = $stationl[1];
 }
diff -urNbwB foltia.r91/install/perl/addpidatq.pl foltia/install/perl/addpidatq.pl
--- foltia.r91/install/perl/addpidatq.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/addpidatq.pl	2009-06-06 18:54:00.000000000 +0900
@@ -13,12 +13,13 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 use Schedule::At;
 use Time::Local;
 
 $path = $0;
 $path =~ s/addpidatq.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -35,20 +36,15 @@
 
 
 #DB検索(PID)
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
-
-$DBQuery =  "SELECT count(*) FROM  foltia_subtitle WHERE pid = '$pid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
+
+$sth = $dbh->prepare($stmt{'addpidatq.1'});
+$sth->execute($pid);
  @titlecount= $sth->fetchrow_array;
  
  if ($titlecount[0]  == 1 ){
-
-$DBQuery =  "SELECT bitrate,digital FROM  foltia_tvrecord , foltia_subtitle  WHERE foltia_tvrecord.tid = foltia_subtitle.tid AND pid='$pid' ";
- $sth = $dbh->prepare($DBQuery);
-$sth->execute();
+    $sth = $dbh->prepare($stmt{'addpidatq.2'});
+    $sth->execute($pid);
  @titlecount= $sth->fetchrow_array;
 $bitrate = $titlecount[0];#ビットレート取得
 if ($titlecount[1] >= 1){
@@ -58,17 +54,15 @@
 }
 
 #PID抽出
-$now = &epoch2foldate(`date +%s`);
+    $now = &epoch2foldate(time());
 
 #stationIDからrecch
-$DBQuery =  "SELECT stationrecch,digitalch ,digitalstationband ,foltia_station.stationid  FROM foltia_station,foltia_subtitle WHERE foltia_subtitle.pid = '$pid'  AND  foltia_subtitle.stationid =  foltia_station.stationid ";
-
- $stationh = $dbh->prepare($DBQuery);
-	$stationh->execute();
-@stationl =  $stationh->fetchrow_array;
+    $stationh = $dbh->prepare($stmt{'addpidatq.3'});
+    $stationh->execute($pid);
+    @stationl =  $stationh->fetchrow_array();
 $recch = $stationl[0];
 if ($recch eq ""){
-	&writelog("addpidatq ERROR recch is NULL:$DBQuery.");
+	&writelog("addpidatq ERROR recch is NULL:$stmt{'addpidatq.3'}.");
 	exit 1;
 }
 if ($stationl[1] => 1){
@@ -81,9 +75,8 @@
 }else{
 	$digitalstationband = 0;
 }
-$DBQuery =  "SELECT  * FROM  foltia_subtitle WHERE pid='$pid' ";
- $sth = $dbh->prepare($DBQuery);
-$sth->execute();
+    $sth = $dbh->prepare($stmt{'addpidatq.4'});
+    $sth->execute($pid);
 ($pid ,
 $tid ,
 $stationid ,
diff -urNbwB foltia.r91/install/perl/captureimagemaker.pl foltia/install/perl/captureimagemaker.pl
--- foltia.r91/install/perl/captureimagemaker.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/captureimagemaker.pl	2009-06-06 18:54:00.000000000 +0900
@@ -13,7 +13,7 @@
 
 $path = $0;
 $path =~ s/captureimagemaker.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -55,7 +55,7 @@
 $date = $filename[2];
 $date =~ s/[^0-9]//ig;
 if ($date eq "" ){
-	$date =  `date  +%Y%m%d`
+    $date = strftime("%Y%m%d", localtime);
 }
 #	print "DATE:$date\n";
 
@@ -64,7 +64,7 @@
 $time = substr($time, 0, 4);
 $time =~ s/[^0-9]//ig;
 if ($time eq "" ){
-	$time =  `date  +%H%M`
+    $time =  strftime("%H%M", localtime);
 }
 #	print "TIME:$time\n";
 
diff -urNbwB foltia.r91/install/perl/changestbch.pl foltia/install/perl/changestbch.pl
--- foltia.r91/install/perl/changestbch.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/changestbch.pl	2009-06-06 18:54:00.000000000 +0900
@@ -25,10 +25,11 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 
 $path = $0;
 $path =~ s/changestbch.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 require 'foltialib.pl';
@@ -53,13 +54,10 @@
 
 # pidから局(送出コマンド)調べる
 #DB初期化
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
-
-$DBQuery =  "SELECT foltia_station.tunertype,foltia_station.tunerch ,foltia_station.stationrecch ,foltia_station.stationid FROM foltia_subtitle,foltia_station WHERE foltia_subtitle.stationid = foltia_station.stationid AND foltia_subtitle.pid =  '$pid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+	$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
+
+	$sth = $dbh->prepare($stmt{'changestbch.1'});
+	$sth->execute($pid);
  @chstatus = $sth->fetchrow_array;
  	$tunertype = $chstatus[0];
 	$tunercmd =  $chstatus[1];
diff -urNbwB foltia.r91/install/perl/db/Pg.pl foltia/install/perl/db/Pg.pl
--- foltia.r91/install/perl/db/Pg.pl	1970-01-01 09:00:00.000000000 +0900
+++ foltia/install/perl/db/Pg.pl	2009-06-06 18:54:01.000000000 +0900
@@ -0,0 +1,79 @@
+
+%main::stmt = (
+'addatq.1' => "SELECT count(*) FROM foltia_tvrecord WHERE tid = ?",
+'addatq.2' => "SELECT count(*) FROM foltia_tvrecord WHERE tid = ? AND stationid = ?",
+'addatq.3' => "SELECT count(*) FROM foltia_tvrecord WHERE tid = ? AND stationid = '0'",
+'addatq.addcue.1' => "SELECT * FROM foltia_tvrecord WHERE tid = ?",
+'addatq.addcue.2' => "SELECT * FROM foltia_tvrecord WHERE tid = ? AND stationid = ?",
+'addatq.addcue.3' => "SELECT * from foltia_subtitle WHERE tid = ? AND startdatetime > ? AND startdatetime < ?",
+'addatq.addcue.4' => "SELECT stationid , stationrecch FROM foltia_station where stationid = ?",
+'addstq.addcue.5' => "SELECT * from foltia_subtitle WHERE tid = ? AND stationid = ? AND startdatetime > ? AND startdatetime < ?",
+'addatq.addcue.6' => "SELECT stationid , stationrecch FROM foltia_station where stationid = ?",
+
+'addpidatq.1' => "SELECT count(*) FROM foltia_subtitle WHERE pid = ?",
+'addpidatq.2' => "SELECT bitrate,digital FROM foltia_tvrecord , foltia_subtitle WHERE foltia_tvrecord.tid = foltia_subtitle.tid AND pid = ?",
+'addpidatq.3' => "SELECT stationrecch, digitalch, digitalstationband ,foltia_station.stationid FROM foltia_station,foltia_subtitle WHERE foltia_subtitle.pid = ? AND foltia_subtitle.stationid = foltia_station.stationid",
+'addpidatq.4' => "SELECT * FROM foltia_subtitle WHERE pid = ?",
+
+'changestbch.1' => "SELECT foltia_station.tunertype, foltia_station.tunerch, foltia_station.stationrecch, foltia_station.stationid FROM foltia_subtitle, foltia_station WHERE foltia_subtitle.stationid = foltia_station.stationid AND foltia_subtitle.pid = ?",
+
+'envpolicyupdate.1' => "SELECT userclass,name,passwd1 FROM foltia_envpolicy",
+
+'foltialib.getstationid.1' => "SELECT count(*) FROM foltia_station WHERE stationname = ?",
+'foltialib.getstationid.2' => "SELECT stationid,stationname FROM foltia_station WHERE stationname = ?",
+'foltialib.getstationid.3' => "SELECT max(stationid) FROM foltia_station",
+'foltialib.getstationid.4' => "INSERT INTO foltia_station (stationid, stationname, stationrecch) VALUES (?, ?, ?)",
+'foltialib.getpidbympegfilename.1' => "SELECT pid FROM foltia_subtitle WHERE m2pfilename = ? LIMIT 1",
+'foltialib.changefilestatus.1' => "UPDATE foltia_subtitle SET filestatus = ?, lastupdate = now() WHERE pid = ?",
+'foltialib.getfilestatus.1' => "SELECT filestatus FROM foltia_subtitle WHERE pid = ?",
+
+'getxml2db.1' => "SELECT count(*) FROM foltia_program WHERE tid = ?",
+'getxml2db.2' => "INSERT into foltia_program VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?)",
+'getxml2db.3' => "SELECT title FROM foltia_program WHERE tid = ?",
+'getxml2db.4' => "UPDATE foltia_program SET title = ? where tid = ?",
+'getxml2db.5' => "SELECT count(*) FROM foltia_subtitle WHERE tid = ? AND pid = ?",
+'getxml2db.6' => "UPDATE foltia_subtitle SET stationid = ?, countno = ?, subtitle = ?, startdatetime = ?, enddatetime = ?, startoffset = ?, lengthmin = ? WHERE tid = ? AND pid = ?",
+'getxml2db.7' => "UPDATE foltia_subtitle SET stationid = ?, countno = ?, subtitle = ?, startdatetime = ?, enddatetime = ?, startoffset = ?, lengthmin = ? WHERE tid = ? AND pid = ?",
+'getxml2db.8' => "INSERT into foltia_subtitle (pid, tid, stationid, countno, subtitle, startdatetime, enddatetime, startoffset, lengthmin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+'getxml2db.9' => "INSERT into foltia_subtitle (pid, tid, stationid, countno, subtitle, startdatetime, enddatetime, startoffset, lengthmin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+
+'ipodtranscode.1' => "SELECT foltia_subtitle.pid,foltia_subtitle.tid,foltia_subtitle.m2pfilename,filestatus,foltia_program.aspect,foltia_subtitle.countno FROM foltia_subtitle, foltia_program, foltia_m2pfiles WHERE filestatus >= ? AND filestatus < ? AND foltia_program.tid = foltia_subtitle.TID AND foltia_program.PSP = 1 AND foltia_m2pfiles.m2pfilename = foltia_subtitle.m2pfilename ORDER BY enddatetime ASC LIMIT 1",
+'ipodtranscode.2' => "SELECT title, countno, subtitle FROM foltia_program, foltia_subtitle WHERE foltia_program.tid = foltia_subtitle.tid AND foltia_subtitle.pid = ?",
+'ipodtranscode.updatemp4file.1' => "UPDATE foltia_subtitle SET PSPfilename = ? WHERE pid = ?",
+'ipodtranscode.updatemp4file.2' => "INSERT INTO foltia_mp4files VALUES (?, ?)",
+
+'ipodtranscode.counttranscodefiles.1' => "SELECT count(*) FROM foltia_subtitle, foltia_program, foltia_m2pfiles WHERE filestatus >= ? AND filestatus < ? AND foltia_program.tid = foltia_subtitle.TID AND foltia_program.PSP = 1 AND foltia_m2pfiles.m2pfilename = foltia_subtitle.m2pfilename",
+
+'mklocalizeddir.1' => "SELECT title FROM foltia_program where tid = ?",
+
+'recwrap.1' => "UPDATE foltia_subtitle SET m2pfilename = ? WHERE pid = ?",
+'recwrap.2' => "INSERT into foltia_m2pfiles VALUES (?)",
+'recwrap.3' => "SELECT psp,aspect,title FROM foltia_program WHERE tid = ?",
+'recwrap.4' => "SELECT subtitle FROM foltia_subtitle WHERE tid = ? AND countno = ?",
+'recwrap.5' => "UPDATE foltia_subtitle SET PSPfilename = ? WHERE pid = ?",
+'recwrap.6' => "INSERT into foltia_mp4files VALUES (?, ?)",
+'recwrap.7' => "SELECT foltia_subtitle.tid,foltia_subtitle.countno,foltia_subtitle.subtitle,foltia_subtitle.startdatetime ,foltia_subtitle.enddatetime ,foltia_subtitle.lengthmin ,foltia_tvrecord.bitrate , foltia_subtitle.startoffset , foltia_subtitle.pid ,foltia_tvrecord.digital FROM foltia_subtitle ,foltia_tvrecord WHERE foltia_tvrecord.tid = foltia_subtitle.tid AND foltia_tvrecord.tid = ? AND foltia_subtitle.startdatetime = ? AND foltia_tvrecord.digital = 1",
+
+'schedulecheck.1' => "SELECT count(*) FROM foltia_tvrecord",
+'schedulecheck.2' => "SELECT tid ,stationid FROM foltia_tvrecord",
+
+'singletranscode.1' => "SELECT pid FROM foltia_subtitle WHERE m2pfilename = ?",
+'singletranscode.2' => "SELECT count(*) FROM foltia_subtitle WHERE tid = ? AND countno = ?",
+'singletranscode.3' => "SELECT count(*) FROM foltia_subtitle WHERE tid = ?",
+'singletranscode.4' => "SELECT psp,aspect,title FROM foltia_program WHERE tid = ?",
+'singletranscode.5' => "SELECT subtitle FROM foltia_subtitle WHERE tid = ? AND countno = ?",
+'singletranscode.6' => "UPDATE foltia_subtitle SET PSPfilename = ? WHERE pid = ?",
+'singletranscode.7' => "INSERT into foltia_mp4files values (?, ?)",
+
+'updatem2pfiletable.1' => "DELETE FROM foltia_m2pfiles",
+'updatem2pfiletable.2' => "INSERT into foltia_m2pfiles values (?)",
+'updatem2pfiletable.3' => "DELETE FROM foltia_mp4files",
+'updatem2pfiletable.4' => "INSERT into foltia_mp4files values (?, ?)",
+
+'xmltv2foltia.chkerase.1' => "DELETE FROM foltia_epg WHERE startdatetime > ? AND ontvchannel = ?",
+'xmltv2foltia.registdb.1' => "SELECT max(epgid) FROM foltia_epg",
+'xmltv2foltia.registdb.2' => "INSERT INTO foltia_epg VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
+
+);
+
+1;
diff -urNbwB foltia.r91/install/perl/db/SQLite.pl foltia/install/perl/db/SQLite.pl
--- foltia.r91/install/perl/db/SQLite.pl	1970-01-01 09:00:00.000000000 +0900
+++ foltia/install/perl/db/SQLite.pl	2009-06-06 18:54:01.000000000 +0900
@@ -0,0 +1,6 @@
+
+require 'db/Pg.pl';
+
+$stmt{'foltialib.changefilestatus.1'} = "UPDATE foltia_subtitle SET filestatus = ?, lastupdate = datetime('now', 'localtime') WHERE pid = ?";
+
+1;
diff -urNbwB foltia.r91/install/perl/deletemovie.pl foltia/install/perl/deletemovie.pl
--- foltia.r91/install/perl/deletemovie.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/deletemovie.pl	2009-06-06 18:54:00.000000000 +0900
@@ -16,7 +16,7 @@
 
 $path = $0;
 $path =~ s/deletemovie.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
diff -urNbwB foltia.r91/install/perl/digitaltvrecording.pl foltia/install/perl/digitaltvrecording.pl
--- foltia.r91/install/perl/digitaltvrecording.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/digitaltvrecording.pl	2009-06-06 18:54:00.000000000 +0900
@@ -24,7 +24,7 @@
 
 $path = $0;
 $path =~ s/digitaltvrecording.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -111,7 +111,7 @@
 		$outputfile = $outputpath.$outputfile ;
 		&writelog("digitaltvrecording: DEBUG FILENAME ne null \$outputfile $outputfile ");
 	}else{
-		$outputfile .= `date  +%Y%m%d-%H%M --date "1 min "`;
+	$outputfile .= strftime("%Y%m%d-%H%M", localtime(time + 60));
 		chomp($outputfile);
 		$outputfile .= ".m2t";
 		$outputfilewithoutpath = $outputfile ;
diff -urNbwB foltia.r91/install/perl/envpolicyupdate.pl foltia/install/perl/envpolicyupdate.pl
--- foltia.r91/install/perl/envpolicyupdate.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/envpolicyupdate.pl	2009-06-06 18:54:00.000000000 +0900
@@ -15,10 +15,11 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 
 $path = $0;
 $path =~ s/envpolicyupdate.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -32,13 +33,9 @@
 $returnparam = getphpstyleconfig("environmentpolicytoken");
 eval "$returnparam\n";
 
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+    $dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
-$DBQuery =  "SELECT userclass,name,passwd1 FROM foltia_envpolicy ";
-
- $envph = $dbh->prepare($DBQuery);
+    $envph = $dbh->prepare($stmt{'envpolicyupdate.1'});
 	$envph->execute();
 
 #なければつくる
diff -urNbwB foltia.r91/install/perl/folprep.pl foltia/install/perl/folprep.pl
--- foltia.r91/install/perl/folprep.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/folprep.pl	2009-06-06 18:54:00.000000000 +0900
@@ -22,7 +22,7 @@
 
 $path = $0;
 $path =~ s/folprep.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
diff -urNbwB foltia.r91/install/perl/foltia_conf1.pl.template foltia/install/perl/foltia_conf1.pl.template
--- foltia.r91/install/perl/foltia_conf1.pl.template	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/foltia_conf1.pl.template	2009-06-09 00:04:21.000000000 +0900
@@ -27,10 +27,15 @@
 $phptoolpath = $toolpath ;#php版の初期設定の位置。デフォルトではperlと同じ位置
 
 #以下はデフォルトでインストールしてればいじらなくてもいい
-$main::DBDriv="Pg";
-$main::DBHost="localhost";
-$main::DBPort="5432";
-$main::DBName="foltia";
+
+## for postgresql
+#$main::DSN="dbi:Pg:dbname=foltia;host=localhost;port=5432";
+#require 'db/Pg.pl';
+
+## for sqlite
+$main::DSN="dbi:SQLite:dbname=/home/foltia/foltia.sqlite";
+require 'db/SQLite.pl';
+
 $main::DBUser="foltia";
 $main::DBPass="";
 
diff -urNbwB foltia.r91/install/perl/foltialib.pl foltia/install/perl/foltialib.pl
--- foltia.r91/install/perl/foltialib.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/foltialib.pl	2009-06-06 18:54:00.000000000 +0900
@@ -3,7 +3,7 @@
 
 $path = $0;
 $path =~ s/foltialib.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 require "foltia_conf1.pl";
@@ -12,12 +12,10 @@
 #  foltia lib
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
+use POSIX qw(strftime);
 
-
-	 $DBDriv=$main::DBDriv;
-	 $DBHost=$main::DBHost;
-	 $DBPort=$main::DBPort;
-	 $DBName=$main::DBName;
+$DSN=$main::DSN;
 	 $DBUser=$main::DBUser;
 	 $DBPass="";
 	
@@ -46,7 +44,7 @@
 #------------------------------
 sub writelog{
 my $messages = $_[0];
-my $timestump = `date  +%Y/%m/%d_%H:%M:%S`;
+    my $timestump = strftime("%Y/%m/%d_%H:%M:%S", localtime);
 chomp($timestump);
 if ($debugmode == 1){
 	open (DEBUGLOG , ">>$toolpath/debuglog.txt") || die "Cant write log file.$! \n ";
@@ -145,19 +143,17 @@
 #戻り値:1
 my $stationname =  $_[0] ;
 my $stationid ;
-my $DBQuery =  "SELECT count(*) FROM foltia_station WHERE stationname = '$item{ChName}'";
 
 my $sth;
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+    $sth = $dbh->prepare($stmt{'foltialib.getstationid.1'});
+    $sth->execute($item{'ChName'});
  my  @stationcount;
  @stationcount= $sth->fetchrow_array;
 
 if ($stationcount[0] == 1){
 #チャンネルID取得
-$DBQuery =  "SELECT stationid,stationname FROM foltia_station WHERE stationname = '$item{ChName}'";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+	$sth = $dbh->prepare($stmt{'foltialib.getstationid.2'});
+	$sth->execute($item{'ChName'});
  @stationinfo= $sth->fetchrow_array;
 #局ID
 $stationid  = $stationinfo[0];
@@ -165,20 +161,17 @@
 
 }elsif($stationcount[0] == 0){
 #新規登録
-$DBQuery =  "SELECT max(stationid) FROM foltia_station";
-	 $sth = $dbh->prepare($DBQuery);
+	$sth = $dbh->prepare($stmt{'foltialib.getstationid.3'});
 	$sth->execute();
  @stationinfo= $sth->fetchrow_array;
 my $stationid = $stationinfo[0] ;
 $stationid  ++;
 ##$DBQuery =  "insert into  foltia_station values ('$stationid'  ,'$item{ChName}','0','','','','','','')";
 #新規局追加時は非受信局をデフォルトに
-$DBQuery =  "insert into  foltia_station  (stationid , stationname ,stationrecch )  values ('$stationid'  ,'$item{ChName}','-10')";
-
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+	$sth = $dbh->prepare($stmt{'foltialib.getstationid.4'});
+	$sth->execute($stationid, $item{'ChName'}, -10);
 #print "Add station;$DBQuery\n";
-&writelog("foltialib Add station;$DBQuery");
+	&writelog("foltialib Add station;$stmt{'foltialib.getstationid.4'}");
 }else{
 
 #print "Error  getstationid $stationcount[0] stations found. $DBQuery\n";
@@ -286,11 +279,10 @@
 	return  0 ;
 }
 
-my $DBQuery =  "SELECT pid FROM foltia_subtitle WHERE m2pfilename = '$m2pfilename' LIMIT 1 ";
 my $sth;
-$sth = $dbh->prepare($DBQuery);
-$sth->execute();
-#print "$DBQuery\n";
+    $sth = $dbh->prepare($stmt{'foltialib.getpidbympegfilename.1'});
+    $sth->execute($m2pfilename);
+#print "$stmt{'foltialib.getpidbympegfilename.1'}\n";
 my @pidinfo = $sth->fetchrow_array;
 my $pid  = $pidinfo[0];
 
@@ -311,10 +303,9 @@
 }
 
 if ($updatestatus > 0 ){
-my $DBQuery =  "UPDATE  foltia_subtitle SET filestatus = $updatestatus , lastupdate 	 = now() WHERE pid = $pid ";
 my $sth;
-$sth = $dbh->prepare($DBQuery);
-$sth->execute();
+	$sth = $dbh->prepare($stmt{'foltialib.changefilestatus.1'});
+	$sth->execute($updatestatus, $pid);
 return 1;
 }else{
 	&writelog("foltialib changefilestatus ERR Sttus invalid:$updatestatus");
@@ -350,10 +341,9 @@
 	return  0 ;
 }
 
-my $DBQuery =  "SELECT filestatus FROM foltia_subtitle  WHERE pid = $pid ";
 my $sth;
-$sth = $dbh->prepare($DBQuery);
-$sth->execute();
+    $sth = $dbh->prepare($stmt{'foltialib.getfilestatus.1'});
+    $sth->execute($pid);
 
 my @statusinfo = $sth->fetchrow_array;
 my $status  = $statusinfo[0];
diff -urNbwB foltia.r91/install/perl/getxml2db.pl foltia/install/perl/getxml2db.pl
--- foltia.r91/install/perl/getxml2db.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/getxml2db.pl	2009-06-06 19:17:07.000000000 +0900
@@ -18,11 +18,12 @@
 use Time::Local;
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 use Digest::MD5 qw(md5_hex);
 
 $path = $0;
 $path =~ s/getxml2db.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 require "foltialib.pl";
@@ -47,13 +48,9 @@
 	#$uri="http://syobocal.orz.hm/cal_chk.xml";
 }
 
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
-
-#$dbh->{AutoCommit} = 0;
+$dbh->{AutoCommit} = 0;
 
 # If-Modified-Since使うように変更#2008/11/14 
 my  $CacheDir = '/tmp/shobocal';
@@ -104,7 +101,8 @@
 $programtitlename =~ s/\&lt\;/</gi;
 $programtitlename =~ s/\&gt\;/>/gi;
 $programtitlename =~ s/\&amp\;/\&/gi;
-$programtitle = $dbh->quote($programtitlename);
+#	$programtitle = $dbh->quote($programtitlename);
+	$programtitle = $programtitlename;
 
 Jcode::convert(\$item{ChName},'euc');
 Jcode::convert(\$item{SubTitle},'euc');
@@ -114,7 +112,7 @@
 $programSubTitle =~ s/\&lt\;/</gi;
 $programSubTitle =~ s/\&gt\;/>/gi;
 $programSubTitle =~ s/\&amp\;/\&/gi;
-$programSubTitle = $dbh->quote($programSubTitle);
+#	$programSubTitle = $dbh->quote($programSubTitle);
 
 $offsetmin = $item{StOffset}/60;
 $edtime = &syobocaldate2foltiadate($item{EdTime});
@@ -126,9 +124,8 @@
 $stationid = &getstationid($item{ChName});
 #サブタイトル追加-------------------------------------------------
 #番組があるか確認
-$DBQuery =  "SELECT count(*) FROM foltia_program WHERE tid = '$item{TID}'";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+	$sth = $dbh->prepare($stmt{'getxml2db.1'});
+	$sth->execute($item{TID});
  @titlecount= $sth->fetchrow_array;
  
  if ($titlecount[0] == 0){
@@ -136,36 +133,29 @@
 
 #200412012359
 $nomalstarttime = substr($sttime,8,4);
-$DBQuery =  "insert into  foltia_program values ($item{TID},$programtitle,'','$nomalstarttime','$length','','','3','1','')";
-# $sth = $dbh->prepare($DBQuery);
-# $sth->execute();
-$oserr = $dbh->do($DBQuery);
-&writelog("getxml2db  ADD TV Progtam:$item{TID}:$programtitle");
-
 
+	    $sth = $dbh->prepare($stmt{'getxml2db.2'});
+	    $oserr = $sth->execute($item{TID}, $programtitle, '', $nomalstarttime, $length, '', '', 3, 1, '', '');
+	    &writelog("getxml2db  ADD TV Progtam:$item{TID}:$programtitle");
 }else{
 #2006/2/26 
 #あったら、タイトル確認して
-$DBQuery =  "SELECT title FROM foltia_program WHERE tid = '$item{TID}'";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+	    $sth = $dbh->prepare($stmt{'getxml2db.3'});
+	    $sth->execute($item{TID});
  @titlearray = $sth->fetchrow_array;
 #更新などされてたらupdate
 #print "$titlearray[0] / $programtitle\n";
  if ($titlearray[0] ne "$programtitlename" ){
- 	$DBQuery =  "UPDATE  foltia_program  SET 	title = $programtitle where  tid = '$item{TID}' ";
-#	  $sth = $dbh->prepare($DBQuery);
-#	$sth->execute();
-	$oserr = $dbh->do($DBQuery);
+		$sth = $dbh->prepare($stmt{'getxml2db.4'});
+		$oserr = $sth->execute($programtitle, $item{TID});
 	&writelog("getxml2db  UPDATE TV Progtam:$item{TID}:$programtitle");
  }#end if update
 }# end if TID
 
 
 #PIDがあるか確認
-$DBQuery =  "SELECT count(*) FROM foltia_subtitle WHERE tid = '$item{TID}' AND pid =  '$item{PID}' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+	$sth = $dbh->prepare($stmt{'getxml2db.5'});
+	$sth->execute($item{'TID'}, $item{'PID'});
  @subticount= $sth->fetchrow_array;
  if ($subticount[0]  >= 1){
 	#PIDあったら上書き更新
@@ -173,50 +163,26 @@
 #	DBD::Pg::st execute failed: ERROR:  invalid input syntax for type bigint: "" at /home/foltia/perl/getxml2db.pl line 147.
 #UPDATE  foltia_subtitle  SET stationid = '42',countno = '8',subtitle = '京都行きます' ,startdatetime = '200503010035'  ,enddatetime = '200503010050',startoffset  = '0' ,lengthmin = '15' WHERE tid = '550' AND pid =  '26000' 
 if ($item{Count} == ""){
-
-	$DBQuery =  "UPDATE  foltia_subtitle  SET 
-	stationid = '$stationid',
-	countno =  null,
-	subtitle = $programSubTitle ,
-	startdatetime = '$recstartdate'  ,
-	enddatetime = '$recenddate',
-	startoffset  = '$offsetmin' ,
-	lengthmin = '$length' 
-	WHERE tid = '$item{TID}' AND pid =  '$item{PID}' ";
-
+		$sth = $dbh->prepare($stmt{'getxml2db.6'});
+		$oserr = $sth->execute($stationid, undef, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length, $item{'TID'}, $item{'PID'});
 }else{
-
-	$DBQuery =  "UPDATE  foltia_subtitle  SET 
-	stationid = '$stationid',
-	countno = '$item{Count}',
-	subtitle = $programSubTitle ,
-	startdatetime = '$recstartdate'  ,
-	enddatetime = '$recenddate',
-	startoffset  = '$offsetmin' ,
-	lengthmin = '$length' 
-	WHERE tid = '$item{TID}' AND pid =  '$item{PID}' ";
-}
-#		 $sth = $dbh->prepare($DBQuery);
-#		$sth->execute();
-	$oserr = $dbh->do($DBQuery);
-
+		$sth = $dbh->prepare($stmt{'getxml2db.7'});
+		$oserr = $sth->execute($stationid, $item{'Count'}, $programSubTitle,  $recstartdate, $recenddate, $offsetmin, $length, $item{'TID'}, $item{'PID'});
+	    }
  }else{
 	#なければ追加
 	
 	#こっちに入る時刻はオフセットされた時刻!
 	#そのままキューに入る形で
 	if ($item{Count} eq ""){
-	$DBQuery = "insert into foltia_subtitle values ( '$item{PID}','$item{TID}','$stationid',null,$programSubTitle,'$recstartdate','$recenddate','$offsetmin' ,'$length')";
+		$sth = $dbh->prepare($stmt{'getxml2db.8'});
+		$oserr = $sth->execute($item{'PID'}, $item{'TID'}, $stationid, undef, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length);
 	}else{
-	$DBQuery = "insert into foltia_subtitle values ( '$item{PID}','$item{TID}','$stationid','$item{Count}',$programSubTitle,'$recstartdate','$recenddate','$offsetmin' ,'$length')";
+		$sth = $dbh->prepare($stmt{'getxml2db.9'});
+		$oserr = $sth->execute($item{'PID'}, $item{'TID'}, $stationid, $item{'Count'}, $programSubTitle, $recstartdate, $recenddate, $offsetmin, $length);
 	}
-#		 $sth = $dbh->prepare($DBQuery);
-#		$sth->execute();
-	$oserr = $dbh->do($DBQuery);
-
 }
 
-
 #print "$DBQuery\n\n\n";
 #debug 20050803
 #&writelog("getxml2db $DBQuery");
@@ -225,7 +190,5 @@
 }#if
 }#foreach
 
-#$oserr = $dbh->commit;
+$oserr = $dbh->commit;
 ##	$dbh->disconnect();
-
-
diff -urNbwB foltia.r91/install/perl/ipodtranscode.pl foltia/install/perl/ipodtranscode.pl
--- foltia.r91/install/perl/ipodtranscode.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/ipodtranscode.pl	2009-06-06 18:54:00.000000000 +0900
@@ -12,11 +12,12 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 use Jcode;
 
 $path = $0;
 $path =~ s/ipodtranscode.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 require "foltialib.pl";
@@ -34,9 +35,7 @@
 }
 
 #DB初期化
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
 # タイトル取得
 #トラコンフラグがたっていてステータス50以上150未満のファイルを古い順にひとつ探す
@@ -56,15 +55,8 @@
 sleep 30;
 
 while ($counttranscodefiles >= 1){
-
-$DBQuery =  "SELECT foltia_subtitle.pid,foltia_subtitle.tid,foltia_subtitle.m2pfilename,filestatus,foltia_program.aspect ,foltia_subtitle.countno 
-FROM foltia_subtitle, foltia_program, foltia_m2pfiles 
-WHERE filestatus >= $FILESTATUSRECEND AND filestatus < $FILESTATUSTRANSCODECOMPLETE  AND foltia_program.tid = foltia_subtitle.TID AND foltia_program.PSP = 1  AND foltia_m2pfiles.m2pfilename = foltia_subtitle.m2pfilename 
-ORDER BY enddatetime ASC 
-LIMIT 1  ";
-
-$sth = $dbh->prepare($DBQuery);
-$sth->execute();
+    $sth = $dbh->prepare($stmt{'ipodtranscode.1'});
+    $sth->execute($FILESTATUSRECEND, $FILESTATUSTRANSCODECOMPLETE, );
 @dbparam = $sth->fetchrow_array;
 #print "$dbparam[0],$dbparam[1],$dbparam[2],$dbparam[3],$dbparam[4],$dbparam[5]\n";
 &writelog("ipodtranscode DEBUG $DBQuery");
@@ -85,13 +77,8 @@
 # 実際のトラコン
 # タイトル取得
 if ($pid ne ""){
-
-$DBQuery =  "SELECT title , countno , subtitle  
-FROM  foltia_program, foltia_subtitle 
-WHERE foltia_program.tid = foltia_subtitle.tid 
-AND foltia_subtitle.pid = $pid ";
-$sth = $dbh->prepare($DBQuery);
-$sth->execute();
+	$sth = $dbh->prepare($stmt{'ipodtranscode.2'});
+	$sth->execute($pid);
 @programtitle = $sth->fetchrow_array;
 $programtitle[0] =~ s/\"/\\"/gi;
 $programtitle[2] =~ s/\"/\\"/gi;
@@ -388,7 +375,7 @@
 &writelog("ipodtranscode DEBUG mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $outputfilename");
 
 if (-e "$pspdirname/$thmfilename"){
-$timestamp =`date "+%Y%m%d-%H%M%S"`;
+	$timestamp = strftime("%Y%m%d-%H%M%S", localtime);
 chomp $timestamp;
 	system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename".$timestamp.".THM");
 }else{
@@ -406,16 +393,14 @@
 
 if (-e "${mp4outdir}MAQ${mp4filenamestring}.MP4"){
 # MP4ファイル名をPIDレコードに書き込み
-	$DBQuery =  "UPDATE foltia_subtitle SET PSPfilename = '$mp4filename' WHERE pid = '$pid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("ipodtranscode UPDATEsubtitleDB $DBQuery");
+	$sth = $dbh->prepare($stmt{'ipodtranscode.updatemp4file.1'});
+	$sth->execute($mp4filename, $pid);
+	&writelog("ipodtranscode UPDATEsubtitleDB $stmt{'ipodtranscode.updatemp4file.1'}");
 
 # MP4ファイル名をfoltia_mp4files挿入
-	$DBQuery = "insert into foltia_mp4files values ('$tid','$mp4filename') ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("ipodtranscode UPDATEmp4DB $DBQuery");
+	$sth = $dbh->prepare($stmt{'ipodtranscode.updatemp4file.2'});
+	$sth->execute($tid, $mp4filename);
+	&writelog("ipodtranscode UPDATEmp4DB $stmt{'ipodtranscode.updatemp4file.2'}");
 
 &changefilestatus($pid,$FILESTATUSALLCOMPLETE);
 }else{
@@ -426,10 +411,8 @@
 }#updatemp4file
 
 sub counttranscodefiles(){
-my $DBQuery =  "SELECT count(*) FROM foltia_subtitle, foltia_program, foltia_m2pfiles 
-WHERE filestatus >= $FILESTATUSRECEND AND filestatus < $FILESTATUSTRANSCODECOMPLETE  AND foltia_program.tid = foltia_subtitle.TID AND foltia_program.PSP = 1  AND foltia_m2pfiles.m2pfilename = foltia_subtitle.m2pfilename  ";
-$sth = $dbh->prepare($DBQuery);
-$sth->execute();
+    $sth = $dbh->prepare($stmt{'ipodtranscode.counttranscodefiles.1'});
+    $sth->execute($FILESTATUSRECEND, $FILESTATUSTRANSCODECOMPLETE);
 my @titlecount= $sth->fetchrow_array;
 
 return ($titlecount[0]);
diff -urNbwB foltia.r91/install/perl/mklocalizeddir.pl foltia/install/perl/mklocalizeddir.pl
--- foltia.r91/install/perl/mklocalizeddir.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/mklocalizeddir.pl	2009-06-06 18:54:00.000000000 +0900
@@ -15,11 +15,11 @@
 use Jcode;
 use DBI;
 use DBD::Pg;
-
+use DBD::SQLite;
 
 $path = $0;
 $path =~ s/mklocalizeddir.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 require "foltialib.pl";
@@ -42,14 +42,11 @@
 #.localized用文字列取得
 
 #接続
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+    $dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
 #検索
-$DBQuery =  "select title from foltia_program where tid=$tid ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+    $sth = $dbh->prepare($stmt{'mklocalizeddir.1'});
+    $sth->execute($tid);
  @subticount= $sth->fetchrow_array;
 $title = $subticount[0] ;
 $titleeuc = $title ;
diff -urNbwB foltia.r91/install/perl/recwrap.pl foltia/install/perl/recwrap.pl
--- foltia.r91/install/perl/recwrap.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/recwrap.pl	2009-06-06 18:54:00.000000000 +0900
@@ -14,13 +14,14 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 use Schedule::At;
 use Time::Local;
 use Jcode;
 
 $path = $0;
 $path =~ s/recwrap.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -45,9 +46,7 @@
 $digitalch= $ARGV[9] ;
 
 #DB初期化
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
 
 if ($usedigital == 1){
@@ -56,7 +55,7 @@
 	$extension = ".m2p";#MPEG2の拡張子
 }
 
-$outputfile = `date  +%Y%m%d-%H%M --date "1 min "`;
+$outputfile = strftime("%Y%m%d-%H%M", localtime(time + 60));
 chomp($outputfile);
 
 if ($tid == 0){
@@ -76,7 +75,7 @@
 #デジタルなら
 &writelog("recwrap RECSTART DIGITAL $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio");
 #録画
-$starttime = (`date +%s`);
+    $starttime = time();
 $oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio");
 $oserr = $oserr / 256;
 
@@ -118,7 +117,7 @@
 
 #録画
 #system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfile $bitrate $tid $countno");
-$starttime = (`date +%s`);
+    $starttime = time();
 
 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno");
 $oserr = $oserr / 256;
@@ -130,9 +129,9 @@
 }#endif #デジタル優先フラグ
 
 #デバイスビジーで即死してないか検出
-$now = (`date +%s`);
+$now = time();
 	if ($now < $starttime + 100){ #録画プロセス起動してから100秒以内に戻ってきてたら
-	$retrycounter == 0;
+    $retrycounter = 0;
 		while($now < $starttime + 100){
 			if($retrycounter >= 5){
 				&writelog("recwrap WARNING  Giving up recording.");
@@ -140,12 +139,12 @@
 			}
 		&writelog("recwrap retry recording $now $starttime");
 		#アナログ録画
-$starttime = (`date +%s`);
+	$starttime = time();
 if($outputfilename =~ /.m2t$/){
 	$outputfilename =~ s/.m2t$/.m2p/;
 }
 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength N $outputfilename $bitrate $tid $countno");
-$now = (`date +%s`);
+	$now = time();
 $oserr = $oserr / 256;
 			if ($oserr == 1){
 				&writelog("recwrap ABORT recfile exist. in resume process.[$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
@@ -159,17 +158,15 @@
 
 
 # m2pファイル名をPIDレコードに書き込み
-	$DBQuery =  "UPDATE foltia_subtitle SET m2pfilename = '$outputfilename' WHERE pid = '$pid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("recwrap DEBUG UPDATEDB $DBQuery");
+$sth = $dbh->prepare($stmt{'recwrap.1'});
+$sth->execute($outputfilename, $pid);
+&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}");
 &changefilestatus($pid,$FILESTATUSRECEND);
 
 # m2pファイル名をPIDレコードに書き込み
-	$DBQuery =  "insert into foltia_m2pfiles values ('$outputfilename')";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("recwrap DEBUG UPDATEDB $DBQuery");
+$sth = $dbh->prepare($stmt{'recwrap.2'});
+$sth->execute($outputfilename);
+&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}");
 
 # Starlight breaker向けキャプチャ画像作成
 if (-e "$toolpath/perl/captureimagemaker.pl"){
@@ -183,9 +180,8 @@
 
 # MPEG4 ------------------------------------------------------
 #MPEG4トラコン必要かどうか
-$DBQuery =  "SELECT psp,aspect,title FROM foltia_program WHERE tid = '$tid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+$sth = $dbh->prepare($stmt{'recwrap.3'});
+$sth->execute($tid);
  @psptrcn= $sth->fetchrow_array;
 if ($psptrcn[0]  == 1 ){#トラコン番組
 &writelog("recwrap Launch ipodtranscode.pl");
@@ -299,7 +295,7 @@
 #タイムスタンプが最新のMP4ファイル名取得
 my $newestmp4filename = `cd $pspdirname ; ls -t *.MP4 | head -1`;
  if ($newestmp4filename =~ /M4V$tid/){
-	$nowcountno = $' ;
+		$nowcountno = $' ;#'
 		$nowcountno++;
 		$pspfilnameft = sprintf("%02d",$nowcountno);
 	while (-e "$pspdirname/M4V".$pspfilnamehd.$pspfilnameft.".MP4"){
@@ -347,7 +343,7 @@
 			}
 			&writelog("recwrap TRCN WAITING :$trcnprocesses / $cpucores :$outputfilename $loadaverage");
 		sleep 113;
-		sleep ($recch)*5;
+	    sleep ($recch); //*5;
 	}
 } until ($trcnprocesses  < $cpucores);
 
@@ -357,9 +353,8 @@
 	system("$toolpath/perl/transcode/vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]");
 	&writelog("recwrap TRCNEND  vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]");
 	#最適化
-	$DBQuery =  "SELECT subtitle  FROM  foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' ";
-		 $sth = $dbh->prepare($DBQuery);
-		$sth->execute();
+	$sth = $dbh->prepare($stmt{'recwrap.4'});
+	$sth->execute($tid, $countno);
 	 @programtitle = $sth->fetchrow_array;
 	if ( $countno == "0" ){
 		$pspcountno = "";
@@ -395,7 +390,7 @@
 &writelog("recwrap THAMI  convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V$pspdirname.THM ");
 
 if (-e "$pspdirname/$thmfilename"){
-$timestamp =`date "+%Y%m%d-%H%M%S"`;
+	$timestamp = strftime("%Y%m%d-%H%M%S", localtime);
 chomp $timestamp;
 	system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename".$timestamp.".THM");
 
@@ -411,22 +406,20 @@
 
 
 # MP4ファイル名をPIDレコードに書き込み
-	$DBQuery =  "UPDATE foltia_subtitle SET PSPfilename = '$mp4filename' WHERE pid = '$pid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("recwrap UPDATEsubtitleDB  $DBQuery");
+    $sth = $dbh->prepare($stmt{'recwrap.5'});
+    $sth->execute($mp4filename, $pid);
+    &writelog("recwrap UPDATEsubtitleDB $stmt{'recwrap.5'}");
 
 # MP4ファイル名をfoltia_mp4files挿入
-	$DBQuery = "insert into foltia_mp4files values ('$tid','$mp4filename') ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("recwrap UPDATEmp4DB  $DBQuery");
+    $sth = $dbh->prepare($stmt{'recwrap.6'});
+    $sth->execute($tid, $mp4filename);
+    &writelog("recwrap UPDATEmp4DB $stmt{'recwrap.6'}");
 
 &changefilestatus($pid,200);
 }#PSPトラコンあり
 
 sub continuousrecordingcheck(){
-my $now = `date  +%s --date "2 min "`;
+    my $now = time() + 60 * 2;
 &writelog("recwrap DEBUG continuousrecordingcheck() now $now");
 my @processes =`ps ax | grep recfriio`;
 
@@ -473,18 +466,10 @@
 		@filenameparts = split(/\./,$starttime);
 		$startdatetime = $startdate.$filenameparts[0];
 		#DBから録画中番組のデータ探す
-	$DBQuery =  "
-SELECT foltia_subtitle.tid,foltia_subtitle.countno,foltia_subtitle.subtitle,foltia_subtitle.startdatetime ,foltia_subtitle.enddatetime ,foltia_subtitle.lengthmin ,foltia_tvrecord.bitrate , foltia_subtitle.startoffset , foltia_subtitle.pid ,foltia_tvrecord.digital 
-FROM foltia_subtitle ,foltia_tvrecord 
-WHERE 
-foltia_tvrecord.tid = foltia_subtitle.tid AND 
-foltia_tvrecord.tid = $tid AND 
-foltia_subtitle.startdatetime = $startdatetime AND 
-foltia_tvrecord.digital = 1";
-	&writelog("recwrap DEBUG continuousrecordingcheck() $DBQuery");
-	$sth = $dbh->prepare($DBQuery);
+		    &writelog("recwrap DEBUG continuousrecordingcheck() $stmt{'recwrap.7'}");
+		    $sth = $dbh->prepare($stmt{'recwrap.7'});
 	&writelog("recwrap DEBUG continuousrecordingcheck() prepare");
-	$sth->execute();
+		    $sth->execute($tid, $startdatetime);
 	&writelog("recwrap DEBUG continuousrecordingcheck() execute");
 	@recfile = $sth->fetchrow_array;
 	&writelog("recwrap DEBUG continuousrecordingcheck() @recfile  $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] $recfile[6] $recfile[7] $recfile[8] $recfile[9] ");
diff -urNbwB foltia.r91/install/perl/schedulecheck.pl foltia/install/perl/schedulecheck.pl
--- foltia.r91/install/perl/schedulecheck.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/schedulecheck.pl	2009-06-06 18:54:00.000000000 +0900
@@ -13,12 +13,13 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 use Schedule::At;
 use Time::Local;
 
 $path = $0;
 $path =~ s/schedulecheck.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -28,28 +29,21 @@
 system("$toolpath/perl/getxml2db.pl");
 
 #予約番組探し
-$now = &epoch2foldate(`date +%s`);
+$now = &epoch2foldate(time());
 $now = &epoch2foldate($now);
 $checkrangetime = $now   + 15*60;#15分後まで
 $checkrangetime =  &epoch2foldate($checkrangetime);
 
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
-$DBQuery =  "SELECT count(*)  FROM foltia_tvrecord ";
-
-
-	 $sth = $dbh->prepare($DBQuery);
+$sth = $dbh->prepare($stmt{'schedulecheck.1'});
 	$sth->execute();
  @titlecount= $sth->fetchrow_array;
 
  if ($titlecount[0]  == 0 ){
 exit;
 }else{
-
-$DBQuery =  "SELECT  tid ,stationid  FROM foltia_tvrecord ";
-	 $sth = $dbh->prepare($DBQuery);
+    $sth = $dbh->prepare($stmt{'schedulecheck.2'});
 	$sth->execute();
 while (($tid,$stationid  ) = $sth->fetchrow_array()) {
 #キュー再投入
diff -urNbwB foltia.r91/install/perl/singletranscode.pl foltia/install/perl/singletranscode.pl
--- foltia.r91/install/perl/singletranscode.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/singletranscode.pl	2009-06-06 18:54:00.000000000 +0900
@@ -27,13 +27,14 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 use Schedule::At;
 use Time::Local;
 use Jcode;
 
 $path = $0;
 $path =~ s/singletranscode.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -62,17 +63,13 @@
 # -- recwrapからほとんどコピー
 
 #PSPトラコン必要かどうか
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
 if ($ARGV[1] != ""){
 	$pid = $ARGV[1] ;
 }else{
-$DBQuery =  "SELECT pid FROM  foltia_subtitle WHERE m2pfilename = '$ARGV[0]' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+    $sth = $dbh->prepare($stmt{'singletranscode.1'});
+    $sth->execute($ARGV[0]);
  @pidarray = $sth->fetchrow_array;
 	unless ($pidarray[0]  == "" ){
 		$pid = $pidarray[0]
@@ -85,15 +82,13 @@
 
 #　追加部分
 
-$query =  "SELECT count(*)  FROM  foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' ";
-	 $sth = $dbh->prepare($query);
-	$sth->execute();
+$sth = $dbh->prepare($stmt{'singletranscode.2'});
+$sth->execute($tid, $countno);
  @subticount= $sth->fetchrow_array;
  unless ($subticount[0]  >= 1){
 
-$query =  "SELECT count(*)  FROM  foltia_subtitle WHERE tid = '$tid'  ";
-	 $sth = $dbh->prepare($query);
-	$sth->execute();
+    $sth = $dbh->prepare($stmt{'singletranscode.3'});
+    $sth->execute($tid);
  @subticount= $sth->fetchrow_array;
 
  unless ($subticount[0]  >= 1){
@@ -119,9 +114,8 @@
 
 # PSP ------------------------------------------------------
 #PSPトラコン必要かどうか
-$DBQuery =  "SELECT psp,aspect,title FROM  foltia_program WHERE tid = '$tid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+$sth = $dbh->prepare($stmt{'singletranscode.4'});
+$sth->execute($tid);
  @psptrcn= $sth->fetchrow_array;
  if ($psptrcn[0]  == 1 ){#トラコン番組
 
@@ -226,7 +219,7 @@
 #タイムスタンプが最新のMP4ファイル名取得
 my $newestmp4filename = `cd $pspdirname ; ls -t *.MP4 | head -1`;
  if ($newestmp4filename =~ /M4V$tid/){
-	$nowcountno = $' ;
+		$nowcountno = $' ;#'
 		$nowcountno++;
 		$pspfilnameft = sprintf("%02d",$nowcountno);
 	while (-e "$pspdirname/M4V".$pspfilnamehd.$pspfilnameft.".MP4"){
@@ -260,9 +253,8 @@
 
 #最適化
 
-$DBQuery =  "SELECT subtitle  FROM  foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
+    $sth = $dbh->prepare($stmt{'singletranscode.5'});
+    $sth->execute($tid, $countno);
  @programtitle = $sth->fetchrow_array;
 
 if ( $countno == "0" ){
@@ -284,7 +276,7 @@
 &writelog("singletranscode THAMI  convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V$pspdirname.THM ");
 
 if (-e "$pspdirname/M4V".$pspfilname.".THM"){
-$timestamp =`date "+%Y%m%d-%H%M%S"`;
+	$timestamp = strftime("%Y%m%d-%H%M%S", localtime);
 chomp $timestamp;
 	system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V".$pspfilname.".THM.".$timestamp.".THM");
 
@@ -296,27 +288,17 @@
 # rm -rf 00000002.jpg  
 system("rm -rf $pspdirname/0000000*.jpg ");
 
-
-
-
 # MP4ファイル名をPIDレコードに書き込み
 unless ($pid eq ""){
-	$DBQuery =  "
-	UPDATE  foltia_subtitle  
-	SET PSPfilename = 'M4V$pspfilname.MP4' 
-	WHERE pid =  '$pid' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("singletranscode UPDATEsubtitleDB  $DBQuery");
+	$sth = $dbh->prepare($stmt{'singletranscode.6'});
+	$sth->execute("M4V$pspfilname.MP4", $pid);
+	&writelog("singletranscode UPDATEsubtitleDB $stmt{'singletranscode.6'}");
 }else{
 &writelog("singletranscode PID not found");
 }
 # MP4ファイル名をfoltia_mp4files挿入
-	$DBQuery =  "insert into  foltia_mp4files values ('$tid','M4V$pspfilname.MP4') ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("singletranscode UPDATEmp4DB  $DBQuery");
+    $sth = $dbh->prepare($stmt{'singletranscode.7'});
+    $sth->execute($tid, "M4V$pspfilname.MP4");
+    &writelog("singletranscode UPDATEmp4DB $stmt{'singletranscode.7'}");
 
 }#PSPトラコンあり
-
-
diff -urNbwB foltia.r91/install/perl/tvrecording.pl foltia/install/perl/tvrecording.pl
--- foltia.r91/install/perl/tvrecording.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/tvrecording.pl	2009-06-06 18:54:01.000000000 +0900
@@ -28,7 +28,7 @@
 
 $path = $0;
 $path =~ s/tvrecording.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
@@ -300,17 +300,17 @@
 #		if ($ARGV[3] =~ /[0-9]{8}-[0-9]{4}/){
 #		$outputfile .= "$ARGV[3]";
 #		}else{
-#		$outputfile .= `date  +%Y%m%d-%H%M --date "1 min "`;
+#		$outputfile .= strftime("%Y%m%d-%H%M", localtime(time + 60));
 #		}
 		$outputfile = $ARGV[3];
 		$outputfile = &filenameinjectioncheck($outputfile);
 		$outputfilewithoutpath = $outputfile ;
 		$outputfile = $outputpath.$outputfile ;
 #		$outputfile .= "$ARGV[3]";		
-#		$outputfile .= `date  +%Y%m%d-%H%M --date "1 min "`;
+#		$outputfile .= strftime("%Y%m%d-%H%M", localtime(time + 60));
 		&writelog("tvrecording:  DEBUG ARGV[2] ne null  \$outputfile $outputfile ");
 	}else{
-		$outputfile .= `date  +%Y%m%d-%H%M --date "1 min "`;
+	$outputfile .= strftime("%Y%m%d-%H%M", localtime(time + 60));
 		chomp($outputfile);
 		$outputfile .= ".m2p";
 		$outputfilewithoutpath = $outputfile ;
diff -urNbwB foltia.r91/install/perl/updatem2pfiletable.pl foltia/install/perl/updatem2pfiletable.pl
--- foltia.r91/install/perl/updatem2pfiletable.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/updatem2pfiletable.pl	2009-06-06 18:54:01.000000000 +0900
@@ -15,28 +15,26 @@
 
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 
 $path = $0;
 $path =~ s/updatem2pfiletable.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 
 require "foltialib.pl";
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
 
 $dbh->{AutoCommit} = 0;
 #　ひとまず消す
-$query =  "DELETE  FROM  foltia_m2pfiles  ";
-	 $sth = $dbh->prepare($query);
+$sth = $dbh->prepare($stmt{'updatem2pfiletable.1'});
 	$sth->execute();
 
 while ($file = glob("$recfolderpath/*.m2?")) {
 $file =~ s/$recfolderpath\///;
-$query =  "insert into  foltia_m2pfiles values ('$file')";
-$oserr = $dbh->do($query);
+    $sth = $dbh->prepare($stmt{'updatem2pfiletable.2'});
+    $sth->execute($file);
 # print "$file\n";
 }#while
 $oserr = $dbh->commit;
@@ -45,8 +43,7 @@
 @mp4filelist = `find ${recfolderpath}/ | grep MP4`;#by foltia dev ticket #5 http://www.dcc-jpl.com/foltia/ticket/5
 
 #　ひとまず消す
-$query =  "DELETE  FROM  foltia_mp4files  ";
-	 $sth = $dbh->prepare($query);
+$sth = $dbh->prepare($stmt{'updatem2pfiletable.3'});
 	$sth->execute();
 
 
@@ -57,8 +54,8 @@
 $filetid = $fileline[0];
 $filetid =~ s/[^0-9]//g;
 if (($filetid ne "" )&& ($fileline[2] ne "" )){
-	$query =  "insert into  foltia_mp4files values ('$filetid','$fileline[2]')";
-	$oserr = $dbh->do($query);
+	$sth = $dbh->prepare($stmt{'updatem2pfiletable.4'});
+	$oserr = $sth->execute($filetid, $fileline[2]);
 #print "$filetid;$fileline[2];$query\n"
 # http://www.atmarkit.co.jp/fnetwork/rensai/sql03/sql1.html
 }#end if
diff -urNbwB foltia.r91/install/perl/xmltv2foltia.pl foltia/install/perl/xmltv2foltia.pl
--- foltia.r91/install/perl/xmltv2foltia.pl	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/perl/xmltv2foltia.pl	2009-06-06 18:54:01.000000000 +0900
@@ -29,23 +29,23 @@
 use Time::Local;
 use DBI;
 use DBD::Pg;
+use DBD::SQLite;
 
 $path = $0;
 $path =~ s/xmltv2foltia.pl$//i;
-if ($pwd  ne "./"){
+if ($path ne "./"){
 push( @INC, "$path");
 }
 require "foltialib.pl";
 
 $currentworkdate = "" ;
 $currentworkch = "" ;
-$today =`date "+%Y%m%d"`;
-$todaytime =`date "+%Y%m%d%H%M"`;
+$today = strftime("%Y%m%d", localtime);
+$todaytime = strftime("%Y%m%d%H%M", localtime);
 
 # DB Connect
-	my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
-		$DBDriv,$DBName,$DBHost,$DBPort);
-	 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
+$dbh->{AutoCommit} = 0;
 
 while(<>){
 #print $_;
@@ -186,15 +186,15 @@
 
 }elsif(/<\/programme>/){
 #登録処理はココで
-#&writelog("xmltv2foltia DEBUG call chkerase $item{start},$item{channel}");
+#&writelog("xmltv2foltia DEBUG call chkerase $item{'start'},$item{'channel'}");
 
-&chkerase($item{start},$item{channel});
-if ($item{subtitle} ne "" ){
-	$registdesc = $item{subtitle}." ".$item{desc};
+	&chkerase($item{'start'}, $item{'channel'});
+	if ($item{'subtitle'} ne "" ){
+	    $registdesc = $item{'subtitle'}." ".$item{'desc'};
 }else{
-	$registdesc = $item{desc};
+	    $registdesc = $item{'desc'};
 }
-&registdb($item{start},$item{stop},$item{channel},$item{title},$registdesc ,$item{category});
+	&registdb($item{'start'},$item{'stop'},$item{'channel'},$item{'title'},$registdesc ,$item{'category'});
 
 #	print "$item{start}
 #$item{stop}
@@ -215,6 +215,11 @@
 }# endif
 }# while
 
+$dbh->commit;
+
+#end
+################
+
 sub chkerase{
 # xmltvからきた日付とチャンネルをfoltia epgと比較
 my $foltiastarttime = $_[0]; # 14桁
@@ -231,10 +236,9 @@
 my $epgstartdatetime = $today * 10000 ; # 200508070000 12桁
 # 新規に入る予定の未来の番組表、全部いったん消す
 # $DBQuery =  "DELETE from foltia_epg where startdatetime > $epgstartdatetime AND ontvchannel = '$ontvepgchannel' ";
- $DBQuery =  "DELETE from foltia_epg where startdatetime > $todaytime AND ontvchannel = '$ontvepgchannel' ";
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-&writelog("xmltv2foltia DELETE EPG $epgstartdatetime:$DBQuery");
+	    $sth = $dbh->prepare($stmt{'xmltv2foltia.chkerase.1'});
+	    $sth->execute($todaytime, $ontvepgchannel);
+	    &writelog("xmltv2foltia DELETE EPG $epgstartdatetime:$stmt{'xmltv2foltia.chkerase.1'}");
 #$currentworkdate = "$today";
 $currentworkch = $ontvepgchannel ;
 }else{
@@ -260,8 +265,7 @@
 
 if($foltiastarttime > $todaytime){
 	
-	my $DBQuery =  "SELECT max(epgid) FROM foltia_epg ";
-		 $sth = $dbh->prepare($DBQuery);
+	$sth = $dbh->prepare($stmt{'xmltv2foltia.registdb.1'});
 		$sth->execute();
 	 @currentepgid = $sth->fetchrow_array;
 	 
@@ -273,20 +277,18 @@
 	}
 #&writelog("xmltv2foltia DEBUG $currentepgid[0] /  $newepgid");
 my $lengthmin = &calclength($foltiastarttime , $foltiaendtime);
-$newepgid = $dbh->quote($newepgid );
-$foltiastarttime = $dbh->quote($foltiastarttime);
-$foltiaendtime = $dbh->quote($foltiaendtime );
-$lengthmin = $dbh->quote($lengthmin );
-$channel = $dbh->quote($channel );
-$title = $dbh->quote($title);
-$desc = $dbh->quote($desc);
-$category = $dbh->quote($category);
-
-$DBQuery =  "insert into  foltia_epg values ($newepgid,$foltiastarttime,$foltiaendtime,$lengthmin,$channel,$title,$desc,$category)";
-#	$DBQuery = $dbh->quote($DBQuery);
-	 $sth = $dbh->prepare($DBQuery);
-	$sth->execute();
-
+#	$newepgid = $dbh->quote($newepgid );
+#	$foltiastarttime = $dbh->quote($foltiastarttime);
+#	$foltiaendtime = $dbh->quote($foltiaendtime );
+#	$lengthmin = $dbh->quote($lengthmin );
+#	$channel = $dbh->quote($channel );
+#	$title = $dbh->quote($title);
+#	$desc = $dbh->quote($desc);
+#	$category = $dbh->quote($category);
+
+	$sth = $dbh->prepare($stmt{'xmltv2foltia.registdb.2'});
+	$sth->execute($newepgid, $foltiastarttime, $foltiaendtime, $lengthmin, $channel, $title, $desc, $category) ||
+	    warn "error: $newepgid, $foltiastarttime, $foltiaendtime, $lengthmin, $channel, $title, $desc, $category\n";
 
 # &writelog("xmltv2foltia DEBUG $DBQuery");
 
diff -urNbwB foltia.r91/install/php/accountregist.php foltia/install/php/accountregist.php
--- foltia.r91/install/php/accountregist.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/accountregist.php	2009-06-06 19:17:07.000000000 +0900
@@ -57,12 +57,12 @@
 //すでにそのユーザが存在しているかどうか確認
 if ($username != ""){
 $query = "
-SELECT memberid ,userclass,name,passwd1 
+SELECT count(memberid)
 FROM foltia_envpolicy 
 WHERE foltia_envpolicy.name  = '$username'  
 ";
 	$isaccountexist = m_query($con, $query, "DBクエリに失敗しました");
-	$isaccountexistncount = pg_num_rows($isaccountexist);
+	$isaccountexistncount = $isaccountexist->fetchColumn(0);
 
 	if ($isaccountexistncount == 0){
 	//valid
@@ -84,13 +84,11 @@
 FROM  foltia_envpolicy 
 ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-	if ($maxrows == 0){
-	$nextcno = 1 ;
+	$maxid = $rs->fetchColumn(0);
+	if ($maxid) {
+		$nextcno = $maxid + 1;
 	}else{
-	$rowdata = pg_fetch_row($rs, 0);
-	$nextcno = $rowdata[0];
-	$nextcno++ ;
+		$nextcno = 1;
 	}
 
 //登録
diff -urNbwB foltia.r91/install/php/delepgp.php foltia/install/php/delepgp.php
--- foltia.r91/install/php/delepgp.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/delepgp.php	2009-06-06 19:17:07.000000000 +0900
@@ -73,12 +73,10 @@
  ";
 
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdate) {
 		die_exit("登録番組がありません<BR>");
 		}
-		$rowdata = pg_fetch_row($rs, 0);
 
 		$pid = htmlspecialchars($rowdata[0]);
 		$stationid = htmlspecialchars($rowdata[1]);
diff -urNbwB foltia.r91/install/php/deletemovie.php foltia/install/php/deletemovie.php
--- foltia.r91/install/php/deletemovie.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/deletemovie.php	2009-05-20 23:34:41.000000000 +0900
@@ -90,7 +86,8 @@
  AND foltia_subtitle.tid = $filesplit[0] 
 ";
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$rowdata = pg_fetch_row($rs, $row);
+				$rall = $rs->fetchAll();
+				$rowdata = $rall[$row];
 //print" $fName./$rowdata[1]//$rowdata[2]<BR>\n";
 $title = $rowdata[1];
 $subtitle = "";
@@ -106,7 +102,8 @@
  AND foltia_subtitle.countno = $filesplit[1] 
 ";
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$rowdata = pg_fetch_row($rs, $row);
+				$rall = $rs->fetchAll();
+				$rowdata = $rall[$row];
 //print" $fName./$rowdata[1]/$rowdata[2]/$rowdata[3]<BR>\n";
 $title = $rowdata[1];
 $count = $rowdata[2];
diff -urNbwB foltia.r91/install/php/delreserve.php foltia/install/php/delreserve.php
--- foltia.r91/install/php/delreserve.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/delreserve.php	2009-06-06 19:17:07.000000000 +0900
@@ -43,12 +43,11 @@
 
 <?php
 
-
-$tid = getgetnumform(tid);
+    $tid = getgetnumform("tid");
 		if ($tid == "") {
 		die_exit("番組がありません<BR>");
 		}
-$sid = getgetnumform(sid);
+    $sid = getgetnumform("sid");
 		if ($sid == "") {
 		die_exit("局がありません<BR>");
 		}
@@ -72,12 +71,10 @@
 WHERE foltia_tvrecord.tid = foltia_program.tid  AND foltia_tvrecord.stationid = foltia_station .stationid  AND foltia_tvrecord.tid = $tid AND foltia_tvrecord.stationid = $sid  ";
 
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdate) {
 		die_exit("登録番組がありません<BR>");
 		}
-		$rowdata = pg_fetch_row($rs, 0);
 
 		$tid = htmlspecialchars($rowdata[0]);
 		$stationname = htmlspecialchars($rowdata[1]);
@@ -167,13 +164,11 @@
 ORDER BY foltia_subtitle.startdatetime  ASC
 ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		echo("放映予定はありません<BR>");
-		}
-		else{
-		$maxcols = pg_num_fields($rs);		
+}else{
+	$maxcols = $rs->columnCount();
 ?>
   <table BORDER="0" CELLPADDING="0" CELLSPACING="2" WIDTH="100%" BGCOLOR="#bcf1be">
 	<thead>
@@ -191,16 +186,13 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
+	     do {
 				echo("<tr>\n");
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
-
 				for ($col = 0; $col < $maxcols; $col++) { /* 列に対応 */
 					echo("<td>".htmlspecialchars($rowdata[$col])."<br></td>\n");
 				}
 				echo("</tr>\n");
-			}
+	     } while ($row = $rs->fetch());
 		}//end if
 		?>
 	</tbody>
diff -urNbwB foltia.r91/install/php/folcast.php foltia/install/php/folcast.php
--- foltia.r91/install/php/folcast.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/folcast.php	2009-06-06 19:17:07.000000000 +0900
@@ -50,7 +50,7 @@
 
 $query = "
 SELECT  foltia_program.tid,foltia_program.title,
-foltia_subtitle.countno , foltia_subtitle.subtitle , foltia_subtitle.startdatetime, foltia_subtitle.pspfilename,foltia_subtitle.lengthmin,foltia_subtitle.enddatetime   FROM foltia_subtitle , foltia_program   WHERE \"pspfilename\" ~~ 'M%%'  AND foltia_program.tid = foltia_subtitle.tid AND foltia_program.tid = $tid   
+foltia_subtitle.countno , foltia_subtitle.subtitle , foltia_subtitle.startdatetime, foltia_subtitle.pspfilename,foltia_subtitle.lengthmin,foltia_subtitle.enddatetime   FROM foltia_subtitle , foltia_program   WHERE \"pspfilename\" LIKE 'M%%'  AND foltia_program.tid = foltia_subtitle.tid AND foltia_program.tid = $tid   
 ORDER BY \"enddatetime\" DESC 
 offset 0 limit  $max 
 	";
@@ -61,13 +61,13 @@
 WHERE foltia_program.tid = $tid   
 ";
 	$titlers = m_query($con, $query, "DBクエリに失敗しました");
-	$rowdata = pg_fetch_row($titlers, 0); 
+	$rowdata = $titlers->fetch();
 	$rsstitle = $rowdata[1];
 }else{
 
 $query = "
 SELECT  foltia_program.tid,foltia_program.title,
-foltia_subtitle.countno , foltia_subtitle.subtitle , foltia_subtitle.startdatetime, foltia_subtitle.pspfilename,foltia_subtitle.lengthmin,foltia_subtitle.enddatetime   FROM foltia_subtitle , foltia_program   WHERE \"pspfilename\" ~~ 'M%%'  AND foltia_program.tid = foltia_subtitle.tid ORDER BY \"enddatetime\" DESC 
+foltia_subtitle.countno , foltia_subtitle.subtitle , foltia_subtitle.startdatetime, foltia_subtitle.pspfilename,foltia_subtitle.lengthmin,foltia_subtitle.enddatetime   FROM foltia_subtitle , foltia_program   WHERE \"pspfilename\" LIKE 'M%%'  AND foltia_program.tid = foltia_subtitle.tid ORDER BY \"enddatetime\" DESC 
 offset 0 limit  $max 
 	";
 	$rsstitle = "新規録画";
@@ -96,15 +96,12 @@
 print $header;
 
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
+$rowdata = $rs->fetch();
 
-if ($maxrows == 0) {
+if (! $rowdata) {
 				//die_exit("No items");	
 }else{
-
-for ($row = 0; $row < $maxrows; $row++) { 
-		$rowdata = pg_fetch_row($rs, $row);
-		
+	do {
 //$title = mb_convert_encoding($rowdata[1],"UTF-8", "EUC-JP");
 $tid =  $rowdata[0];
 $title = $rowdata[1];
@@ -162,7 +159,7 @@
 $item = mb_convert_encoding($item,"UTF-8", "EUC-JP");
 print $item ;
 
-}//for
+	} while ($rowdata = $rs->fetch()); //do
 
 }//if
 		?>
diff -urNbwB foltia.r91/install/php/foltia_config2.php.template foltia/install/php/foltia_config2.php.template
--- foltia.r91/install/php/foltia_config2.php.template	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/foltia_config2.php.template	2009-06-09 00:04:21.000000000 +0900
@@ -26,10 +26,8 @@
 		$usedigital = 1;//Friioなどでデジタル録画をするか 1:する 0:しない
 
 // データベース接続設定
-        define("DATABASE_NAME", "foltia");
-        define("DBHOST", "localhost");
-        define("USER_NAME"    , "foltia"    );
-        define("USER_PASSWORD", "passwd"    );
+// define("DSN", "pgsql:host=localhost dbname=foltia user=foltia password= ");
+define("DSN", "sqlite:/home/foltia/foltia.sqlite");
 
 //        $mylocalip = "192.168.0.177" ; //動いている機械のIPアドレス
 
diff -urNbwB foltia.r91/install/php/foltialib.php foltia/install/php/foltialib.php
--- foltia.r91/install/php/foltialib.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/foltialib.php	2009-06-06 19:17:07.000000000 +0900
@@ -94,6 +94,7 @@
 	}
 	
 	/* LIKE 用の文字列のエスケープ */
+/* unused
 	function escape_like($sql, $quote = TRUE) {
 		return ($quote ? "'" : "") .
 		       str_replace(array("\\\\",     "%"    , "_"    ),
@@ -101,6 +102,7 @@
 		                   pg_escape_string($sql)) .
 		       ($quote ? "'" : "");
 	}
+*/
 	
 	/* SQL 文字列のエスケープ */
 	function escape_string($sql, $quote = FALSE) {
@@ -109,6 +111,7 @@
 		}
 		return ($quote ? "'" : "") .
 		       pg_escape_string($sql) .
+	    //sqlite_escape_string($sql) .
 		       ($quote ? "'" : "");
 	}
 	
@@ -125,55 +128,52 @@
 	
 	/* PostgreSQL サーバに接続 */
 	function m_connect() { 
-/*		$con = @pg_connect("host=".DBHOST ." dbname=".DATABASE_NAME .
-		                   " user=".USER_NAME .
-		                   " password=".USER_PASSWORD);
-*/
-		$con = @pg_pconnect("host=".DBHOST ." dbname=".DATABASE_NAME .
-		                   " user=".USER_NAME .
-		                   " password=".USER_PASSWORD);
-
-
-		if (!$con) {
-			die_exit("データベースに接続出来ませんでした。");
+	try {
+		$dbh = new PDO(DSN);
+		$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+		return($dbh);
+	} catch (PDOException $e) {
+		die_exit($e->getMessage() . ": データベースに接続出来ませんでした。");
 		}
 		/* データベースと、PHP の内部文字コードが違う場合 */
-		return($con);
 	}
 
 	/* データベースとの接続を切り離す */
-	function m_close($con) {
-		return @pg_close($con);
+function m_close($dbh) {
+	return null;
 	}
 
 	/* SQL 文を実行 */
-	function m_query($con, $query, $errmessage) {
-		$rtn = @pg_query($con, $query);
-		if (!$rtn) {
+function m_query($dbh, $query, $errmessage) {
+	try {
+		$rtn = $dbh->query($query);
+		return($rtn);
+	} catch (PDOException $e) {
 			/* エラーメッセージに SQL 文を出すのはセキュリティ上良くない！！ */
 			$msg = $errmessage . "<br>\n" .
-			       @pg_last_error($con) . "<br>\n" .
+		    $e->getMessage() . "<br>\n" .
+		    var_export($e->errorInfo, true) . "<br>\n" .
 			       "<small><code>" . htmlspecialchars($query) .
 			       "</code></small>\n";
-			       $rtn = @pg_query($con, "rollback");//04.4.8
-			m_close($con);
+//		$dbh->rollBack();
+		$dbh = null;
 			die_exit($msg);
 		}
-		return($rtn);
 	}
 
 	/* select した結果をテーブルで表示 */
 	function m_showtable($rs) {
 		/* 検索件数 */
-		$maxrows = pg_num_rows($rs);
+	$maxrows = 0;
 		
-		if ($maxrows == 0) {
+	$rowdata = $rs->fetch();
+	if (! $rowdata) {
 			echo("<p class=\"msg\">データが存在しません</p>\n");
 			return 0;
 		}
 		
 		/* フィールド数 */
-		$maxcols = pg_num_fields($rs);
+	$maxcols = $rs->columnCount();
 		?>
 <table class="list" summary="データ検索結果を表示" border="1">
 	<thead>
@@ -182,7 +182,8 @@
 				/* テーブルのヘッダーを出力 */
 				for ($col = 1; $col < $maxcols; $col++) {
 					/* pg_field_name() はフィールド名を返す */
-					$f_name = htmlspecialchars(pg_field_name($rs, $col));
+		     $meta = $rs->getColumnMeta($col);
+		     $f_name = htmlspecialchars($meta["name"]);
 					echo("<th abbr=\"$f_name\">$f_name</th>\n");
 				}
 			?>
@@ -191,10 +192,10 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
+	      do {
+		      $maxrows++;
+
 				echo("<tr>\n");
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
 				/* １列目にリンクを張る */
 				echo("<td><a href=\"edit.php?q_code=" .
 				     urlencode($rowdata[0]) . "\">" .
@@ -203,7 +204,7 @@
 					echo("<td>".htmlspecialchars($rowdata[$col])."<br></td>\n");
 				}
 				echo("</tr>\n");
-			}
+	      } while ($rowdata = $rs->fetch());
 		?>
 	</tbody>
 </table>
@@ -212,8 +213,9 @@
 	}
 
 	/* 指定したコードのデータを表示 */
-	function m_viewdata($con, $code) {
+function m_viewdata($dbh, $code) {
 		/* コードに該当するデータを検索 */
+/*
 		$query = "
 select p.code
       ,p.name
@@ -224,34 +226,45 @@
       ,to_char(p.editdate, 'YYYY/MM/DD HH24:MI:SS') as editdate
   from inet_profile p left join inet_job s on p.job = s.code
  where p.code = $code";
-		$rs = m_query($con, $query, "個人情報の取得に失敗しました。");
-		if (pg_num_rows($rs) == 0) {
+*/
+	$query = "
+select p.code
+      ,p.name
+      ,p.email
+      ,p.pseudonym
+      ,s.name as job
+      ,p.profile
+      ,datetime(p.editdate) as editdate
+  from inet_profile p left join inet_job s on p.job = s.code
+ where p.code = $code";
+	$rs = m_query($dbh, $query, "個人情報の取得に失敗しました。");
+	$rowdata = $rs->fetch();
+	if (! $rowdata) {
 			echo("<p class=\"msg\">データが存在しません</p>\n");
 			return FALSE;
 		}
 		
 		/* フィールド数 */
-		$maxcols = pg_num_fields($rs);
-		/* 先頭行 */
-		$rowdata = pg_fetch_row($rs, 0);
+	$maxcols = $rs->columnCount();
 		?>
 <table class="view" summary="データベース上のデータを表示" border="1">
 	<tr>
-		<td class="name"><?= htmlspecialchars(pg_field_name($rs, 1)) ?></td>
+	     <?php $meta = $rs->getColumnMeta(1); ?>
+	     <td class="name"><?= htmlspecialchars($meta["name"]) ?></td>
 		<td><a href="edit.php?q_code=<?= $rowdata[0] ?>"
 		     ><?= htmlspecialchars($rowdata[1]) ?></a></td>
 	</tr>
-	<?php for ($col = 2; $col < $maxcols; $col++) { ?>
+	     <?php for ($col = 2; $col < $maxcols; $col++) {
+		$meta = $rs->getColumnMeta($col); ?>
 	<tr>
-		<td class="name"><?= htmlspecialchars(pg_field_name($rs, $col)) ?></td>
+	    <td class="name"><?= htmlspecialchars($meta["name"]) ?></td>
 		<td><?= htmlspecialchars($rowdata[$col]) ?></td>
 	</tr>
 	<?php } ?>
 </table>
 		<?php
 		/* クエリーを解放 */
-		pg_free_result($rs);
-		
+      $rs = null;
 		return TRUE;
 	}
 	
@@ -293,17 +306,14 @@
 ORDER BY foltia_epg.startdatetime  ASC
 	";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-if ($maxrows == 0) {
+	$rowdata = $rs->fetch();
+	if (! $rowdata) {
 		print("番組データがありません<BR>");			
 }else{
 print "<table width=\"100%\"  border=\"0\">\n";
 //print "<ul><!-- ($maxrows) $query -->\n";
 
-for ($row = 0; $row < $maxrows; $row++) { 
-	 
-$rowdata = pg_fetch_row($rs, $row);
-
+		do {
 $printstarttime = substr($rowdata[0],8,2) . ":" .  substr($rowdata[0],10,2);
 $tdclass = "t".substr($rowdata[0],8,2) .  substr($rowdata[0],10,2);
 $title = htmlspecialchars($rowdata[3]);
@@ -322,7 +332,7 @@
 $printstarttime  <A HREF=\"./reserveepg.php?epgid=$epgid\">$title</A> $desc($rowdata[0] - $rowdata[1])
 </li>\n";
 */
-}//for
+		} while ($rowdata = $rs->fetch());//do
 //print "</ul>\n";
 print "</table>\n";
 
@@ -556,20 +566,22 @@
 WHERE foltia_envpolicy.name  = '$name'  
 	";
 	$useraccount = m_query($con, $query, "DBクエリに失敗しました");
-	$useraccountrows = pg_num_rows($useraccount);
+		$rowdata = $useraccount->fetch();
+		if (! $rowdata) {
+			header("HTTP/1.0 401 Unauthorized");
+			redirectlogin();
+		}
 	
-	if ($useraccountrows == 1 ){
-		$rowdata = pg_fetch_row($useraccount, 0);
 		$memberid = $rowdata[0];
 		$userclass = $rowdata[1];
 		$username =  $rowdata[2];
 		$dbpasswd = $rowdata[3];
-	}else{
+
+		$rowdata = $useraccount->fetch();
+		if ($rowdata) {
 		header("HTTP/1.0 401 Unauthorized");
-		//print "<!-- DEBUG DB record error ($useraccountrows)-->";
 		redirectlogin();
-	}//end if
-
+		}
 
 // passwdをdbから取りだし
 if ($userclass == 0){
@@ -626,15 +638,19 @@
 WHERE foltia_envpolicy.name  = '$username'  
 	";
 		$useraccount = m_query($con, $query, "DBクエリに失敗しました");
-	$useraccountrows = pg_num_rows($useraccount);
+		$rowdata = $useraccount->fetch();
+		if (! $rowdata) {
+			return (99);
+		}
 	
-	if ($useraccountrows == 1 ){
-		$rowdata = pg_fetch_row($useraccount, 0);
-		//$userclass = $rowdata[1];
-		return ($rowdata[1]);
-	}else{
-	return (99);//エラー
-	}//end if
+		$userclass = $rowdata[1];
+
+		$rowdata = $useraccount->fetch();
+		if ($rowdata) {
+			return (99);
+		}
+
+		return ($userclass);
 	
 }else{
 	return (0);//環境ポリシー使わないときはつねに特権モード
@@ -654,15 +670,19 @@
 WHERE foltia_envpolicy.name  = '$username'  
 	";
 		$useraccount = m_query($con, $query, "DBクエリに失敗しました");
-	$useraccountrows = pg_num_rows($useraccount);
-	
-	if ($useraccountrows == 1 ){
-		$rowdata = pg_fetch_row($useraccount, 0);
-		//$userclass = $rowdata[1];
-		return ($rowdata[0]);
-	}else{
+		$rowdata = $useraccount->fetch();
+		if (! $rowdata) {
 	return (-1);//エラー
-	}//end if
+		}
+
+		$memberid = $rowdata[0];
+
+		$rowdata = $useraccount->fetch();
+		if ($rowdata) {
+			return (-1);
+		}
+
+		return ($memberid);
 	
 }else{
 	return (0);//環境ポリシー使わないときはつねに特権モード
@@ -681,20 +701,23 @@
 WHERE foltia_envpolicy.memberid  = '$memberid'  
 	";
 		$useraccount = m_query($con, $query, "DBクエリに失敗しました");
-	$useraccountrows = pg_num_rows($useraccount);
-	
-	if ($useraccountrows == 1 ){
-		$rowdata = pg_fetch_row($useraccount, 0);
-		return ($rowdata[2]);
-	}else{
+		$rowdata = $useraccount->fetch();
+		if (! $rowdata) {
 	return ("");//エラー
-	}//end if
+		}
 	
-}else{
+		$name = $rowdata[2];
+
+		$rowdata = $useraccount->fetch();
+		if ($rowdata) {
 	return ("");
-}//end if
+		}
 
+		return ($name);
 
+	}else{
+		return ("");
+	}//end if
 
 }//end function getmemberid2name
 
diff -urNbwB foltia.r91/install/php/graytable.css foltia/install/php/graytable.css
--- foltia.r91/install/php/graytable.css	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/graytable.css	2009-05-20 07:16:20.000000000 +0900
@@ -1,4 +1,4 @@
-body * {margin:0px;padding:0px;border:0px;}
+// body * {margin:0px;padding:0px;border:0px;}
 
 body {
 	color: #555;
diff -urNbwB foltia.r91/install/php/index.php foltia/install/php/index.php
--- foltia.r91/install/php/index.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/index.php	2009-06-06 19:17:07.000000000 +0900
@@ -71,64 +71,51 @@
 LIMIT 1000
 	";
 	$reservedrssametid = m_query($con, $query, "DBクエリに失敗しました");
-	$reservedmaxrowssameid = pg_num_rows($reservedrssametid);
-	
-	if ($reservedmaxrowssameid > 0 ){
-	for ($rrow = 0; $rrow < $reservedmaxrowssameid ; $rrow++) {
-		$rowdata = pg_fetch_row($reservedrssametid, $rrow);
+$rowdata = $reservedrssametid->fetch();
+if ($rowdata) {
+	do {
 		$reservedpidsametid[] = $rowdata[7];
-	}
+	} while ($rowdata = $reservedrssametid->fetch());
+
 	$rowdata = "";
-	$rrow = ""; 
 	}else{
-	$reservedpidsametid = "" ;
+	$reservedpidsametid = array();
 	}//end if
+$reservedrssametid->closeCursor();
 
 //録画番組検索
 $query = "
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate ,
-foltia_subtitle.pid  
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime as x, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate, foltia_subtitle.pid
 FROM foltia_subtitle , foltia_program ,foltia_station ,foltia_tvrecord
 WHERE foltia_tvrecord.tid = foltia_program.tid AND foltia_tvrecord.stationid = foltia_station .stationid AND foltia_program.tid = foltia_subtitle.tid AND foltia_station.stationid = foltia_subtitle.stationid
 AND foltia_subtitle.enddatetime >= '$now'
 UNION
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate ,
-foltia_subtitle.pid  
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate, foltia_subtitle.pid
 FROM foltia_tvrecord
 LEFT OUTER JOIN foltia_subtitle on (foltia_tvrecord.tid = foltia_subtitle.tid )
 LEFT OUTER JOIN foltia_program on (foltia_tvrecord.tid = foltia_program.tid )
 LEFT OUTER JOIN foltia_station on (foltia_subtitle.stationid = foltia_station.stationid )
 WHERE foltia_tvrecord.stationid = 0 AND
-foltia_subtitle.enddatetime >= '$now' ORDER BY \"startdatetime\" ASC 
+ foltia_subtitle.enddatetime >= '$now' ORDER BY x ASC
 LIMIT 1000
 	";
 
 	$reservedrs = m_query($con, $query, "DBクエリに失敗しました");
-	$reservedmaxrows = pg_num_rows($reservedrs);
-	
-	if ($reservedmaxrows > 0 ){
-	for ($rrow = 0; $rrow < $reservedmaxrows ; $rrow++) {
-		$rowdata = pg_fetch_row($reservedrs, $rrow);
+$rowdata = $reservedrs->fetch();
+if ($rowdata) {
+	do {
 		$reservedpid[] = $rowdata[8];
-	}
+	} while ($rowdata = $reservedrs->fetch());
 	}else{
-	$reservedpid = "";
+	$reservedpid = array();
 	}//end if
 
 $mode = getgetform(mode);
@@ -137,49 +124,34 @@
 //新番組表示モード
 	$query = "
 	SELECT 
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin  , 
-foltia_subtitle.pid ,
-foltia_subtitle.startoffset   
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_subtitle.pid, foltia_subtitle.startoffset
 FROM foltia_subtitle , foltia_program ,foltia_station  
 WHERE foltia_program.tid = foltia_subtitle.tid AND foltia_station.stationid = foltia_subtitle.stationid 
  AND foltia_subtitle.enddatetime >= '$now'  AND foltia_subtitle.countno = '1' 
 ORDER BY foltia_subtitle.startdatetime  ASC 
 LIMIT 1000
 	";
-	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-
-
 }else{
 	$query = "
 	SELECT 
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin , 
-foltia_subtitle.pid  , 
-foltia_subtitle.startoffset   
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_subtitle.pid, foltia_subtitle.startoffset
 FROM foltia_subtitle , foltia_program ,foltia_station  
 WHERE foltia_program.tid = foltia_subtitle.tid AND foltia_station.stationid = foltia_subtitle.stationid 
  AND foltia_subtitle.enddatetime >= '$now'  
 ORDER BY foltia_subtitle.startdatetime  ASC 
 LIMIT 1000
 	";
-	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-
 }//end if
 
-if ($maxrows == 0) {
+$rs = m_query($con, $query, "DBクエリに失敗しました");
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 header("Status: 404 Not Found",TRUE,404);
 printtitle();
 print "<body BGCOLOR=\"#ffffff\" TEXT=\"#494949\" LINK=\"#0047ff\" VLINK=\"#000000\" ALINK=\"#c6edff\" >
@@ -210,7 +182,7 @@
 
 <?
 		/* フィールド数 */
-		$maxcols = pg_num_fields($rs);
+    $maxcols = $rs->columnCount();
 		?>
   <table BORDER="0" CELLPADDING="0" CELLSPACING="2" WIDTH="100%">
 	<thead>
@@ -229,10 +201,7 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
-
+     do {
 //他局で同一番組録画済みなら色変え
 if (in_array($rowdata[7], $reservedpidsametid)) {
 $rclass = "reservedtitle";
@@ -282,7 +251,7 @@
 					echo("<td>".htmlspecialchars($rowdata[6])."<br></td>\n");
 
 				echo("</tr>\n");
-			}
+     } while ($rowdata = $rs->fetch());
 		?>
 	</tbody>
 </table>
diff -urNbwB foltia.r91/install/php/listreserve.php foltia/install/php/listreserve.php
--- foltia.r91/install/php/listreserve.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/listreserve.php	2009-06-06 19:17:07.000000000 +0900
@@ -61,46 +61,32 @@
 }
 	$query = "
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate  , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid , 
-foltia_subtitle.epgaddedby , 
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime as x, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate, foltia_subtitle.startoffset,
+ foltia_subtitle.pid, foltia_subtitle.epgaddedby,
 foltia_tvrecord.digital 
 FROM foltia_subtitle , foltia_program ,foltia_station ,foltia_tvrecord
 WHERE foltia_tvrecord.tid = foltia_program.tid AND foltia_tvrecord.stationid = foltia_station .stationid AND foltia_program.tid = foltia_subtitle.tid AND foltia_station.stationid = foltia_subtitle.stationid
 AND foltia_subtitle.enddatetime >= '$now'
 UNION
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid , 
-foltia_subtitle.epgaddedby , 
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate,  foltia_subtitle.startoffset,
+ foltia_subtitle.pid,  foltia_subtitle.epgaddedby,
 foltia_tvrecord.digital 
 FROM foltia_tvrecord
 LEFT OUTER JOIN foltia_subtitle on (foltia_tvrecord.tid = foltia_subtitle.tid )
 LEFT OUTER JOIN foltia_program on (foltia_tvrecord.tid = foltia_program.tid )
 LEFT OUTER JOIN foltia_station on (foltia_subtitle.stationid = foltia_station.stationid )
 WHERE foltia_tvrecord.stationid = 0 AND
-foltia_subtitle.enddatetime >= '$now' ORDER BY \"startdatetime\" ASC
+ foltia_subtitle.enddatetime >= '$now' ORDER BY x ASC
 	";
 
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
 
 //チューナー数
 if (getgetnumform(r) != ""){
@@ -121,13 +107,12 @@
 <p align="left">録画予約番組放映予定と予約番組名を表示します。</p>
 
 <?
-	if ($maxrows == 0) {
+     $rowdata = $rs->fetch();
+     if (! $rowdata) {
 		print "番組データがありません<BR>\n";			
 		}else{
-
-
 		/* フィールド数 */
-		$maxcols = pg_num_fields($rs);
+	     $maxcols = $rs->columnCount();
 		?>
   <table BORDER="0" CELLPADDING="0" CELLSPACING="2" WIDTH="100%">
 	<thead>
@@ -148,10 +133,9 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
+		  do {
 				echo("<tr>\n");
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
+
 $pid = htmlspecialchars($rowdata[9]);
 
 $tid = htmlspecialchars($rowdata[0]);
@@ -167,34 +151,22 @@
 //オンボードチューナー録画
 $query = "
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate  , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid  , 
-foltia_tvrecord.digital 
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate, foltia_subtitle.startoffset,
+ foltia_subtitle.pid, foltia_tvrecord.digital
 FROM foltia_subtitle , foltia_program ,foltia_station ,foltia_tvrecord
 WHERE foltia_tvrecord.tid = foltia_program.tid AND foltia_tvrecord.stationid = foltia_station .stationid AND foltia_program.tid = foltia_subtitle.tid AND foltia_station.stationid = foltia_subtitle.stationid
 AND foltia_subtitle.enddatetime > '$rowdata[5]' 
 AND foltia_subtitle.startdatetime < '$endtime'  
 UNION
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate  , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid , 
-foltia_tvrecord.digital 
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate, foltia_subtitle.startoffset,
+ foltia_subtitle.pid, foltia_tvrecord.digital
 FROM foltia_tvrecord
 LEFT OUTER JOIN foltia_subtitle on (foltia_tvrecord.tid = foltia_subtitle.tid )
 LEFT OUTER JOIN foltia_program on (foltia_tvrecord.tid = foltia_program.tid )
@@ -205,13 +177,14 @@
 	";
 	$rclass = "";
 	$overlap = m_query($con, $query, "DBクエリに失敗しました");
-	$overlapmaxrows = pg_num_rows($overlap);
+			  $owrowall = $overlap->fetchAll();
+			  $overlapmaxrows = count($owrowall);
 	if ($overlapmaxrows > ($recunits) ){
 		
 		$owtimeline = array();
 		
 		for ($rrow = 0; $rrow < $overlapmaxrows ; $rrow++) {
-			$owrowdata = pg_fetch_array($overlap, $rrow);
+					  $owrowdata = $owrowall[$rrow];
 			$owtimeline[ $owrowdata['startdatetime'] ] = $owtimeline[ $owrowdata['startdatetime'] ] +1;
 			
 			$owrend = calcendtime( $owrowdata['startdatetime'], $owrowdata['lengthmin'] );
@@ -236,17 +209,11 @@
 $externalinputs = 1; //現状一系統のみ
 $query = "
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate  , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid  , 
-foltia_tvrecord.digital 
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate, foltia_subtitle.startoffset,
+ foltia_subtitle.pid, foltia_tvrecord.digital
 FROM foltia_subtitle , foltia_program ,foltia_station ,foltia_tvrecord
 WHERE foltia_tvrecord.tid = foltia_program.tid AND foltia_tvrecord.stationid = foltia_station .stationid AND foltia_program.tid = foltia_subtitle.tid AND foltia_station.stationid = foltia_subtitle.stationid
 AND foltia_subtitle.enddatetime > '$rowdata[5]' 
@@ -254,17 +221,11 @@
 AND  (foltia_station.stationrecch = '0' OR  foltia_station.stationrecch = '-1' ) 
 UNION
 SELECT
-foltia_program .tid,
-stationname,
-foltia_program .title,
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate  , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid , 
-foltia_tvrecord.digital 
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_subtitle.countno, foltia_subtitle.subtitle,
+ foltia_subtitle.startdatetime, foltia_subtitle.lengthmin,
+ foltia_tvrecord.bitrate, foltia_subtitle.startoffset,
+ foltia_subtitle.pid, foltia_tvrecord.digital
 FROM foltia_tvrecord
 LEFT OUTER JOIN foltia_subtitle on (foltia_tvrecord.tid = foltia_subtitle.tid )
 LEFT OUTER JOIN foltia_program on (foltia_tvrecord.tid = foltia_program.tid )
@@ -273,16 +234,16 @@
 foltia_subtitle.enddatetime > '$rowdata[5]'  
 AND foltia_subtitle.startdatetime < '$endtime'  
 AND  (foltia_station.stationrecch = '0' OR  foltia_station.stationrecch = '-1' ) 
-
 	";
 	$eoverlap = m_query($con, $query, "DBクエリに失敗しました");
-	$eoverlapmaxrows = pg_num_rows($eoverlap);
+			  $eowrowall = $eoverlap->fetchAll();
+			  $eoverlapmaxrows = count($eowrowall);
 	if ($eoverlapmaxrows > ($externalinputs) ){
 		
 		$eowtimeline = array();
 		
 		for ($erow = 0; $erow < $eoverlapmaxrows ; $erow++) {
-			$eowrowdata = pg_fetch_array($eoverlap, $erow);
+					  $eowrowdata = $eowrowall[$erow];
 			$eowtimeline[ $eowrowdata['startdatetime'] ] = $eowtimeline[ $eowrowdata['startdatetime'] ] +1;
 			
 			$eowrend = calcendtime( $eowrowdata['startdatetime'], $eowrowdata['lengthmin'] );
@@ -358,7 +319,7 @@
 					}
 					echo("<br></td>\n");
 				echo("</tr>\n");
-			}
+		  } while ($rowdata = $rs->fetch());
 		?>
 	</tbody>
 </table>
@@ -373,29 +334,23 @@
 
 
 <?php
-} //if ($maxrows == 0) {
-
-
+    } //if ($maxrows == 0)
 	$query = "
 SELECT 
-foltia_program.tid,
-stationname,
-foltia_program .title ,
-foltia_tvrecord.bitrate ,
-foltia_tvrecord.stationid , 
+ foltia_program.tid, stationname, foltia_program.title,
+ foltia_tvrecord.bitrate, foltia_tvrecord.stationid, 
 foltia_tvrecord.digital   
 FROM  foltia_tvrecord , foltia_program , foltia_station 
 WHERE foltia_tvrecord.tid = foltia_program.tid  AND foltia_tvrecord.stationid = foltia_station .stationid 
 ORDER BY foltia_program.tid  DESC
 ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();			
+if (! $rowdata) {
 //なければなにもしない
 			
 		}else{
-		$maxcols = pg_num_fields($rs);
+	$maxcols = $rs->columnCount();
 
 ?>
 <p align="left">録画予約番組タイトルを表示します。</p>
@@ -416,10 +371,7 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
-
+	     do {
 				$tid = htmlspecialchars($rowdata[0]);
 				
 				if ($tid > 0){
@@ -467,7 +419,7 @@
 					}
 				echo("\n</tr>");
 				}//if tid 0
-			}//for
+	     } while ($rowdata = $rs->fetch());
 		}//else
 		?>
 	</tbody>
diff -urNbwB foltia.r91/install/php/m.php foltia/install/php/m.php
--- foltia.r91/install/php/m.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/m.php	2009-06-06 19:17:07.000000000 +0900
@@ -98,12 +98,8 @@
 FROM foltia_station 
 WHERE stationid = $recstid";
 	$stationvalid = m_query($con, $query, "DBクエリに失敗しました");
-	$stationcount = pg_num_rows($stationvalid);
-
-	if ($stationcount == 1){
-		$recstationname = pg_fetch_row($stationvalid, 0);
-	//valid
-	}else{
+		$recstationname = $stationvalid->fetch();
+		if (! $recstationname) {
 		$errflag = 3;
 		$errmsg = "放送局設定が異常です。";
 	}
@@ -128,22 +124,20 @@
 //min pidを探す
 $query = "SELECT min(pid) FROM  foltia_subtitle ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-	if ($maxrows == 0){
+			$rowdata = $rs->fetch();
+			if (! $rowdata) {
 	$insertpid = -1 ;
 	}else{
-	$rowdata = pg_fetch_row($rs, 0);
 	$insertpid = $rowdata[0];
 	$insertpid-- ;
 	}
 // next 話数を探す
 $query = "SELECT max(countno) FROM  foltia_subtitle WHERE tid = 0";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-	if ($maxrows == 0){
+			$rowdata = $rs->fetch();
+			if (! $rowdata) {
 	$nextcno = 1 ;
 	}else{
-	$rowdata = pg_fetch_row($rs, 0);
 	$nextcno = $rowdata[0];
 	$nextcno++ ;
 	}
@@ -214,27 +208,25 @@
   <p>録画局:
 <?php
 $query = "
-SELECT stationid,stationname,stationrecch ,digitalch 
+SELECT stationid as x, stationname, stationrecch, digitalch
 FROM foltia_station 
 WHERE stationrecch > 0 
 UNION 
 SELECT DISTINCT  stationid,stationname,stationrecch ,digitalch 
 FROM  foltia_station 
 WHERE digitalch > 0
-ORDER BY \"stationid\" ASC";
+ ORDER BY x ASC";
 
-	$stations = m_query($con, $query, "DBクエリに失敗しました");
-	$stationcount = pg_num_rows($stations);
-	
-if ($stationcount > 0 ){
-	for ($row = 0; $row < $stationcount ; $row++) {
-		$rowdata = pg_fetch_row($stations, $row);
+$stationcount = $stations->rowCount();
+		   $rowdata = $stations->fetch();
+		   if ($rowdata) {
+			   do {
 			if ($recstid == $rowdata[0]){
 			print " <input name=\"recstid\" type=\"radio\" value=\"$rowdata[0]\" checked />  $rowdata[1] ($rowdata[2]ch)　\n";
 			}else{
 				print " <input name=\"recstid\" type=\"radio\" value=\"$rowdata[0]\" />  $rowdata[1] ($rowdata[2]ch)　\n";
 			}
-	}
+			   } while ($rowdata = $stations->fetch());
 }else{
 print "放送局データベースが正しくセットアップされていません。録画可能局がありません";
 }
@@ -246,11 +238,9 @@
 ORDER BY \"stationid\" ASC";
 
 	$stations = m_query($con, $query, "DBクエリに失敗しました");
-	$stationcount = pg_num_rows($stations);
-	
-if ($stationcount > 0 ){
-	for ($row = 0; $row < $stationcount ; $row++) {
-		$rowdata = pg_fetch_row($stations, $row);
+$rowdata = $stations->fetch();	
+if ($rowdata) {
+	do {
 		if ($rowdata[0] != 0){
 			if ($recstid == $rowdata[0]){
 			print " <input name=\"recstid\" type=\"radio\" value=\"$rowdata[0]\" checked />  $rowdata[1]　\n";
@@ -259,7 +249,7 @@
 			}
 
 		}
-	}
+	} while ($rowdata = $stations->fetch());
 }
 /*
 print "<p>デジタル録画を優先:";
diff -urNbwB foltia.r91/install/php/reservecomp.php foltia/install/php/reservecomp.php
--- foltia.r91/install/php/reservecomp.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/reservecomp.php	2009-06-06 19:17:07.000000000 +0900
@@ -68,12 +65,10 @@
 //タイトル取得
 	$query = "select title from foltia_program where tid='$tid'";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		$title = "(未登録)";
 		}else{
-		$rowdata = pg_fetch_row($rs, 0);
 		$title = htmlspecialchars($rowdata[0]);
 		}
 
@@ -129,13 +124,12 @@
 
 }
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		echo("放映予定はいまのところありません<BR>");
 		}
 		else{
-		$maxcols = pg_num_fields($rs);		
+	$maxcols = $rs->columnCount();
 ?>
   <table BORDER="0" CELLPADDING="0" CELLSPACING="2" WIDTH="100%" BGCOLOR="#bcf1be">
 	<thead>
@@ -154,16 +148,13 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
+       do {
 				echo("<tr>\n");
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
-
 				for ($col = 0; $col < $maxcols; $col++) { /* 列に対応 */
 					echo("<td>".htmlspecialchars($rowdata[$col])."<br></td>\n");
 				}
 				echo("</tr>\n");
-			}
+       } while ($rowdata = $rs->fetch());
 		}//end if
 		?>
 	</tbody>
@@ -176,33 +167,22 @@
 //foltia_tvrecord　書き込み
 //既存が予約あって、新着が全局予約だったら
 if ($station ==0){
-	$query = "
-SELECT 
- * 
-FROM foltia_tvrecord  
-WHERE tid = '$tid' 
-";
-	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-	if ($maxrows > 0){
 	//既存局を消す
 		$query = "DELETE 
 FROM foltia_tvrecord  
 WHERE tid = '$tid' 
 ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-		}
 }//endif
 
 	$query = "
 SELECT 
- * 
+count(*) 
 FROM foltia_tvrecord  
 WHERE tid = '$tid'  AND stationid = '$station' 
 ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-
+	$maxrows = $rs->fetchColumn(0);
 		if ($maxrows == 0) { //新規追加
 				$query = "INSERT INTO  foltia_tvrecord  values ('$tid','$station','$bitrate','$usedigital')";
 				$rs = m_query($con, $query, "DB書き込みに失敗しました");
diff -urNbwB foltia.r91/install/php/reserveepg.php foltia/install/php/reserveepg.php
--- foltia.r91/install/php/reserveepg.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/reserveepg.php	2009-06-06 19:17:07.000000000 +0900
@@ -58,12 +56,11 @@
 	WHERE epgid='$epgid' AND foltia_station.ontvcode = foltia_epg.ontvchannel
 	";//4812
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		die_exit("登録番組がありません<BR>");
 		}
-		$rowdata = pg_fetch_row($rs, 0);
+
 		//$title = htmlspecialchars($rowdata[0]);
 ?>
 <body BGCOLOR="#ffffff" TEXT="#494949" LINK="#0047ff" VLINK="#000000" ALINK="#c6edff" >
@@ -135,17 +132,11 @@
 //重複確認
 $query = "
 SELECT
-foltia_program .title,
-foltia_program .tid,
-stationname,
-foltia_station.stationid ,  
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate  , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid  
+ foltia_program.title, foltia_program.tid, stationname,
+ foltia_station.stationid, foltia_subtitle.countno,
+ foltia_subtitle.subtitle, foltia_subtitle.startdatetime,
+ foltia_subtitle.lengthmin, foltia_tvrecord.bitrate,
+ foltia_subtitle.startoffset, foltia_subtitle.pid
 FROM foltia_subtitle , foltia_program ,foltia_station ,foltia_tvrecord
 WHERE foltia_tvrecord.tid = foltia_program.tid AND foltia_tvrecord.stationid = foltia_station .stationid AND foltia_program.tid = foltia_subtitle.tid AND foltia_station.stationid = foltia_subtitle.stationid
 AND foltia_subtitle.startdatetime ='$startfoltime'  
@@ -153,17 +144,11 @@
 AND foltia_station.stationid = '$stationid'   
 UNION
 SELECT
-foltia_program .title,
-foltia_program .tid,
-stationname,
-foltia_station.stationid ,  
-foltia_subtitle.countno,
-foltia_subtitle.subtitle,
-foltia_subtitle.startdatetime ,
-foltia_subtitle.lengthmin ,
-foltia_tvrecord.bitrate , 
-foltia_subtitle.startoffset , 
-foltia_subtitle.pid  
+ foltia_program.title, foltia_program.tid, stationname,
+ foltia_station.stationid, foltia_subtitle.countno,
+ foltia_subtitle.subtitle, foltia_subtitle.startdatetime,
+ foltia_subtitle.lengthmin, foltia_tvrecord.bitrate,
+ foltia_subtitle.startoffset, foltia_subtitle.pid
 FROM foltia_tvrecord
 LEFT OUTER JOIN foltia_subtitle on (foltia_tvrecord.tid = foltia_subtitle.tid )
 LEFT OUTER JOIN foltia_program on (foltia_tvrecord.tid = foltia_program.tid )
@@ -174,20 +159,16 @@
 AND foltia_station.stationid =  '$stationid'  
 ";
 
-
-
-	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-
 //print "<!--$query \n $maxrows\n -->";
 
 print "<form name=\"recordingsetting\" method=\"POST\" action=\"reserveepgcomp.php\">\n";
 
-		if ($maxrows == 0) {
+$rs = m_query($con, $query, "DBクエリに失敗しました");
+$chkoverwrap = $rs->fetch();
+if (! $chkoverwrap) {
 		//重複なし
 		print "<input type=\"submit\" value=\"予約\" ><br>\n";
 		}else{
-		$chkoverwrap = pg_fetch_row($rs, 0);
 		$prereservedtitle = htmlspecialchars($chkoverwrap[0]);
 		$tid =  htmlspecialchars($chkoverwrap[1]);
 		$pid =  htmlspecialchars($chkoverwrap[2]);
diff -urNbwB foltia.r91/install/php/reserveepgcomp.php foltia/install/php/reserveepgcomp.php
--- foltia.r91/install/php/reserveepgcomp.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/reserveepgcomp.php	2009-06-06 19:17:07.000000000 +0900
@@ -72,12 +69,10 @@
 //min pidを探す
 $query = "SELECT min(pid) FROM  foltia_subtitle ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-	if ($maxrows == 0){
+	$rowdata = $rs->fetch();
+	if (! $rowdata) {
 	$insertpid = -1 ;
 	}else{
-	$rowdata = pg_fetch_row($rs, 0);
-	
 	$insertpid = $rowdata[0];
 		if ($insertpid > 0){
 		$insertpid = -1;
@@ -88,11 +83,10 @@
 // next 話数を探す
 $query = "SELECT max(countno) FROM  foltia_subtitle WHERE tid = 0";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-	if ($maxrows == 0){
+	$rowdata = $rs->fetch();
+	if (! $rowdata) {
 	$nextcno = 1 ;
 	}else{
-	$rowdata = pg_fetch_row($rs, 0);
 	$nextcno = $rowdata[0];
 	$nextcno++ ;
 	}
diff -urNbwB foltia.r91/install/php/reserveprogram.php foltia/install/php/reserveprogram.php
--- foltia.r91/install/php/reserveprogram.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/reserveprogram.php	2009-06-06 19:17:07.000000000 +0900
@@ -54,12 +52,11 @@
 //タイトル取得
 	$query = "select title from foltia_program where tid='$tid'";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		die_exit("登録番組がありません<BR>");
 		}
-		$rowdata = pg_fetch_row($rs, 0);
+
 		$title = htmlspecialchars($rowdata[0]);
 ?>
 <body BGCOLOR="#ffffff" TEXT="#494949" LINK="#0047ff" VLINK="#000000" ALINK="#c6edff" >
@@ -104,25 +101,22 @@
 ";
 
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		echo("放映局情報がまだはいってません<BR>");
 		}
 		else{
-		$maxcols = pg_num_fields($rs);
+	$maxcols = $rs->columnCount();
 		
 			echo("<select name=\"station\">\n");
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
+	do {
 				echo("<option value=\"");
 				echo(htmlspecialchars($rowdata[0]));
 				echo("\">");
 				echo(htmlspecialchars($rowdata[1]));
 				echo("</option>\n");
-			}//for
+	} while ($rowdata = $rs->fetch());
 			echo("<option value=\"0\">全局</option>\n</select>\n");
 		}//endif		
 	?>
@@ -185,13 +179,12 @@
 ORDER BY foltia_subtitle.startdatetime  ASC
 ";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		echo("放映予定はありません<BR>");
 		}
 		else{
-		$maxcols = pg_num_fields($rs);		
+	$maxcols = $rs->columnCount();
 ?>
   <table BORDER="0" CELLPADDING="0" CELLSPACING="2" WIDTH="100%" BGCOLOR="#bcf1be">
 	<thead>
@@ -209,11 +202,8 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
+       do {
 				echo("<tr>\n");
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
-
 				for ($col = 0; $col < $maxcols; $col++) { /* 列に対応 */
 					if ($col == 3){
 					echo("<td>".htmlspecialchars(foldate2print($rowdata[$col]))."<br></td>\n");
@@ -222,7 +212,7 @@
 					}
 				}
 				echo("</tr>\n");
-			}
+       } while ($rowdata = $rs->fetch());
 		}//end if
 		?>
 	</tbody>
diff -urNbwB foltia.r91/install/php/selectcaptureimage.php foltia/install/php/selectcaptureimage.php
--- foltia.r91/install/php/selectcaptureimage.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/selectcaptureimage.php	2009-06-06 19:17:07.000000000 +0900
@@ -77,8 +75,8 @@
  
 	";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-$rows = pg_num_rows($rs);
-if ($rows == 0){
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 	print "  <p align=\"left\"><font color=\"#494949\" size=\"6\">キャプチャ画像</font></p>
   <hr size=\"4\">
 <p align=\"left\">
@@ -86,8 +84,6 @@
 ";
 
 }else{
-$rowdata = pg_fetch_row($rs, 0);
-
 print "  <p align=\"left\"><font color=\"#494949\" size=\"6\">キャプチャ画像</font></p>
   <hr size=\"4\">
 <p align=\"left\">";
diff -urNbwB foltia.r91/install/php/showlib.php foltia/install/php/showlib.php
--- foltia.r91/install/php/showlib.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/showlib.php	2009-06-06 19:17:07.000000000 +0900
@@ -84,10 +84,8 @@
 ";
 
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-
-$maxrows = pg_num_rows($rs);
-
-if ($maxrows > 0 ){
+$rowdata = $rs->fetch();
+if ($rowdata) {
 if(ereg("iPhone",$useragent)){
 	print "<ul id=\"home\" title=\"録画ライブラリ表示\" selected=\"true\">";
 }else{
@@ -104,8 +102,7 @@
 	<tbody>
 ";
 }
-for ($row = 0; $row < $maxrows; $row++) {
-	$rowdata = pg_fetch_row($rs, $row);
+	do {
 $title = $rowdata[1];
 $counts = $rowdata[2];
 $tid = htmlspecialchars($rowdata[0]);
@@ -124,7 +121,7 @@
 </tr>\n
 ";
 }
-}//for
+	} while ($rowdata = $rs->fetch());
 
 if(ereg("iPhone",$useragent)){
 	print "</ul>\n</body>\n</html>\n";
@@ -159,7 +155,7 @@
 WHERE foltia_program.tid = $filesplit[0] 
 ";
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$rowdata = pg_fetch_row($rs, $row);
+$rowdata = $rs->fetch();
 //print" $fName./$rowdata[1]/$rowdata[2]/$rowdata[3]<BR>\n";
 $title = $rowdata[1];
 
diff -urNbwB foltia.r91/install/php/showlibc.php foltia/install/php/showlibc.php
--- foltia.r91/install/php/showlibc.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/showlibc.php	2009-06-06 19:17:07.000000000 +0900
@@ -70,8 +70,8 @@
 WHERE foltia_program.tid = $tid  
 ";
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$maxrows = pg_num_rows($rs);
-if ($maxrows == 0 ){
+$rowdata = $rs->fetch();
+if (! $rowdata) {
  $syobocaldb = `curl "http://cal.syoboi.jp/db?Command=TitleLookup&TID=$tid" | head -2 `;
 $syobocaldb = mb_convert_encoding($syobocaldb, "EUC-JP", "UTF-8");
 	$syobocaldb = preg_match("/<Title>.*<\/Title>/", $syobocaldb,$title);
@@ -79,7 +79,6 @@
 	$title = strip_tags($title);
 	$title =  htmlspecialchars($title) ;
 }else{
-$rowdata = pg_fetch_row($rs, 0);
 $title = $rowdata[0];
 $title =  htmlspecialchars($title) ;
 }
@@ -148,8 +146,8 @@
 
 $rs = "";
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$maxrows = pg_num_rows($rs);
-if ($maxrows > 0 ){
+$rowdata = $rs->fetch();
+if ($rowdata) {
 if(ereg("iPhone",$useragent)){
 	print "<ul id=\"home\" title=\"$title\" selected=\"true\">";
 }else{
@@ -158,9 +156,7 @@
 	<tbody>
 ";
 }
-for ($row = 0; $row < $maxrows; $row++) {
-	$rowdata = pg_fetch_row($rs, $row);
-
+	do {
 $title = $rowdata[1];
 
 if ($rowdata[2]== "" ){
@@ -194,10 +190,10 @@
 $onairdate = "$day $time";
 }
 //Starlight Breaker向け拡張
-//$debug_pg_num_rows = pg_num_rows ($rs );
+//$debug_pg_num_rows = $rs ->rowCount();
 $caplink = "";
 
-if (($sbpluginexist == 1) && (pg_num_rows ($rs ) > 0)){
+		if ($sbpluginexist == 1) {
  //$capimgpath = htmlspecialchars(preg_replace("/.m2p/", "", $rowdata[5]));
  $capimgpath = htmlspecialchars(preg_replace("/.m2./", "", $rowdata[5]));
  	
@@ -243,7 +239,7 @@
 
 }//endif iPhone
 
-}//for
+	} while ($rowdata = $rs->fetch());
 }else{
 print "録画ファイルがありません<br>\n";
 }//if
diff -urNbwB foltia.r91/install/php/showplaylist.php foltia/install/php/showplaylist.php
--- foltia.r91/install/php/showplaylist.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/showplaylist.php	2009-06-06 19:17:07.000000000 +0900
@@ -117,7 +113,8 @@
  AND foltia_subtitle.tid = $filesplit[0] 
 ";
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$rowdata = pg_fetch_row($rs, $row);
+				$rall = $rs->fetchAll();
+				$rowdata = $rall[$row];
 //print" $fName./$rowdata[1]//$rowdata[2]<BR>\n";
 $title = $rowdata[1];
 $subtitle = "";
@@ -133,7 +129,8 @@
  AND foltia_subtitle.countno = $filesplit[1] 
 ";
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$rowdata = pg_fetch_row($rs, $row);
+				$rall = $rs->fetchAll();
+				$rowdata = $rall[$row];
 //print" $fName./$rowdata[1]/$rowdata[2]/$rowdata[3]<BR>\n";
 $title = $rowdata[1];
 $count = $rowdata[2];
@@ -197,12 +193,9 @@
 }
 
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$maxrows = pg_num_rows($rs);
-
-if ($maxrows > 0){
-for ($row = 0; $row < $maxrows; $row++) { 
-$rowdata = pg_fetch_row($rs, $row);
-
+$rowdata = $rs->fetch();
+if ($rowdata) {
+	do {
 $tid = htmlspecialchars($rowdata[0]);
 $title = htmlspecialchars($rowdata[1]);
 $count = htmlspecialchars($rowdata[2]);
@@ -234,7 +227,7 @@
 	}
 print "</tr>\n
 ";
-}//for
+	} while ($rowdata = $rs->fetch());
 }else{
 print "
 <tr>
@@ -262,10 +254,8 @@
 ";
 
 $rs = m_query($con, $query, "DBクエリに失敗しました");
-$maxrows = pg_num_rows($rs);
-
-
-if ($maxrows > 0){
+	$rowdata = $rs->fetch();
+	if ($rowdata) {
 print "<hr>
 <p align=\"left\">未読タイトルを表示します。<br>
   <table BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"2\" WIDTH=\"100%\">
@@ -278,9 +268,7 @@
 	<tbody>
 ";
 
-for ($row = 0; $row < $maxrows; $row++) { 
-$rowdata = pg_fetch_row($rs, $row);
-
+		do {
 $tid = htmlspecialchars($rowdata[0]);
 $title = htmlspecialchars($rowdata[1]);
 
@@ -284,10 +272,9 @@
 $tid = htmlspecialchars($rowdata[0]);
 $title = htmlspecialchars($rowdata[1]);
 
-
 print "<tr><td>$tid</td><td>$title</td></tr>\n";
 
-}//for
+		} while ($rowdata = $rs->fetch());
 print "</tbody></table>\n";
 }//if maxrows
 }//if title
diff -urNbwB foltia.r91/install/php/titlelist.php foltia/install/php/titlelist.php
--- foltia.r91/install/php/titlelist.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/titlelist.php	2009-06-06 19:17:07.000000000 +0900
@@ -51,13 +51,10 @@
 ORDER BY foltia_program.tid  DESC
 	";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-			
-		if ($maxrows == 0) {
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 		die_exit("番組データがありません<BR>");
-			
 		}
-
 ?>
 
 <body BGCOLOR="#ffffff" TEXT="#494949" LINK="#0047ff" VLINK="#000000" ALINK="#c6edff" >
@@ -71,7 +68,7 @@
 
 <?
 		/* フィールド数 */
-		$maxcols = pg_num_fields($rs);
+$maxcols = $rs->columnCount();
 		?>
   <table BORDER="0" CELLPADDING="0" CELLSPACING="2" WIDTH="100%">
 	<thead>
@@ -85,10 +82,9 @@
 	<tbody>
 		<?php
 			/* テーブルのデータを出力 */
-			for ($row = 0; $row < $maxrows; $row++) { /* 行に対応 */
+    do {
 				echo("<tr>\n");
-				/* pg_fetch_row で一行取り出す */
-				$rowdata = pg_fetch_row($rs, $row);
+
 				//TID
 					echo("<td><a href=\"reserveprogram.php?tid=" .
 				     htmlspecialchars($rowdata[0])  . "\">" .
@@ -99,7 +95,7 @@
 				     htmlspecialchars($rowdata[1]) . "</a></td>\n");
 					print "<td><A HREF = \"showlibc.php?tid=".htmlspecialchars($rowdata[0])."\">mp4</A></td>\n";
 				echo("</tr>\n");
-			}
+    } while ($rowdata = $rs->fetch());
 		?>
 	</tbody>
 </table>
diff -urNbwB foltia.r91/install/php/view_syabas.php foltia/install/php/view_syabas.php
--- foltia.r91/install/php/view_syabas.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/view_syabas.php	2009-06-06 19:17:07.000000000 +0900
@@ -59,14 +57,11 @@
  
 	";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-
-$rows = pg_num_rows($rs);
-if ($rows == 0){
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 	print "";
 	exit;
 }else{
-$rowdata = pg_fetch_row($rs, 0);
-
 $title = $rowdata[2];
 $episode = $rowdata[3];
 $subtitle = $rowdata[4];
diff -urNbwB foltia.r91/install/php/viewepg.php foltia/install/php/viewepg.php
--- foltia.r91/install/php/viewepg.php	2009-05-17 12:00:12.000000000 +0900
+++ foltia/install/php/viewepg.php	2009-06-06 19:17:07.000000000 +0900
@@ -90,11 +88,9 @@
 // $page = 1 ~ 
 $maxdisplay = 8;
 
-	$query = "SELECT stationid, stationname, stationrecch, ontvcode FROM foltia_station WHERE \"ontvcode\" ~~ '%ontvjapan%' 
-	";
+$query = "SELECT count(*) FROM foltia_station WHERE \"ontvcode\" LIKE '%ontvjapan%'";
 	$rs = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrows = pg_num_rows($rs);
-
+$maxrows = $rs->fetchColumn(0);
 if ($maxrows > $maxdisplay){
 	$pages = ceil($maxrows / $maxdisplay) ;
 }
@@ -137,15 +131,15 @@
 //・局リスト
 $query = "SELECT stationid, stationname, stationrecch, ontvcode 
 FROM foltia_station 
-WHERE \"ontvcode\" ~~ '%ontvjapan%'  
+WHERE \"ontvcode\" LIKE '%ontvjapan%'  
 ORDER BY stationid ASC , stationrecch 
-OFFSET $offset LIMIT $maxdisplay 
+LIMIT $maxdisplay OFFSET $offset
 ";
+
 $slistrs = m_query($con, $query, "DBクエリに失敗しました");
-$stations =  pg_num_rows($slistrs);
-for ($i=0 ; $i < $stations ; $i++){
-	$rowdata = pg_fetch_row($slistrs, $i);
-	$stationhash[$i] = $rowdata[3] ;
+while ($rowdata = $slistrs->fetch()) {
+	$stationhash[] = $rowdata[3];
+	$snames[] = $rowdata[1]; // headder
 }
 
 //・時間と全順番のハッシュ作る
@@ -157,9 +151,9 @@
 WHERE foltia_epg.ontvchannel in (
 	SELECT ontvcode 
 	FROM foltia_station 
-	WHERE \"ontvcode\" ~~ '%ontvjapan%'  
+	WHERE \"ontvcode\" LIKE '%ontvjapan%'  
 	ORDER BY stationid ASC , stationrecch 
-	OFFSET $offset LIMIT $maxdisplay
+	LIMIT $maxdisplay OFFSET $offset
 	)
 AND startdatetime  >= $start  
 AND startdatetime  < $epgend  
@@ -169,24 +163,22 @@
 
 //print "$query<br>\n";
 
-$colmnums =  pg_num_rows($rs);
-if ($colmnums == 0){
+$rowdata = $rs->fetch();
+if (! $rowdata) {
 //番組データがない
 $colmnums = 2;
 }else{
-	for ($i=0 ; $i < $colmnums ; $i++){
-		$rowdata = pg_fetch_row($rs, $i);
-		$timetablehash["$rowdata[0]"] = ($i + 1);
+	$colmnums = 0;
+	do {
+		$colmnums++;
+		$timetablehash[$rowdata[0]] = $colmnums;
 //		print "$rowdata[0]:$i+1 <br>\n";
-	}
+	} while ($rowdata = $rs->fetch());
 }
 //print "colmnums $colmnums <br>\n";
 
 //・局ごとに縦に配列入れていく
-for ($j=0 ; $j < $stations ; $j++){
-	$rowdata = pg_fetch_row($slistrs, $j);
-	$stationname = $rowdata[3];
-
+foreach ($stationhash as $stationname) {
 $epgstart = $start ;
 $epgend = calcendtime($start , (8*60));
 $query = "
@@ -197,20 +189,14 @@
 startdatetime  < $epgend  
 ORDER BY foltia_epg.startdatetime  ASC
 	";
-	$statiodh = m_query($con, $query, "DBクエリに失敗しました");
-	$maxrowsstation = pg_num_rows($statiodh);
-
-//print "maxrowsstation $maxrowsstation  stationname $stationname<br>\n";
 
-if ($maxrowsstation == 0) {
+	$statiodh = m_query($con, $query, "DBクエリに失敗しました");
+	$stationrowdata = $statiodh->fetch();
+	if (! $stationrowdata) {
 		//print("番組データがありません<BR>");
 		$item[0]["$stationname"] =  ">番組データがありません";
 }else{
-
-for ($srow = 0; $srow < $maxrowsstation ; $srow++) { 
-	 
-$stationrowdata = pg_fetch_row($statiodh, $srow);
-
+		do {
 $printstarttime = substr($stationrowdata[0],8,2) . ":" .  substr($stationrowdata[0],10,2);
 $tdclass = "t".substr($stationrowdata[0],8,2) .  substr($stationrowdata[0],10,2);
 $title = $stationrowdata[3];
@@ -234,7 +220,7 @@
 $item["$number"]["$stationname"] =  " id=\"$epgcategory\" onClick=\"location = './reserveepg.php?epgid=$epgid'\"><span id=\"epgstarttime\">$printstarttime</span> <A HREF=\"./reserveepg.php?epgid=$epgid\"><span id=\"epgtitle\">$title</span></A> <span id=\"epgdesc\">$desc</span></span>";
 }//if
 
-}//for
+		} while ($stationrowdata = $statiodh->fetch());
 }//if
 
 //・局ごとに間隔決定
@@ -290,15 +276,13 @@
 print "<table>\n<tr>";
 
 //ヘッダ
-for ($i=0;$i<$stations;$i++){
-	$rowdata = pg_fetch_row($slistrs, $i);
-	print "<th>".htmlspecialchars($rowdata[1])."</th>" ;
+foreach ($snames as $s) {
+	print "<th>".htmlspecialchars($s)."</th>" ;
 }
 //本体
 for ($l = 0 ;$l <  $colmnums; $l++){
 	print "<tr>";
-	for ($m = 0 ; $m < $stations ; $m++ ){
-		$stationname = $stationhash[$m];
+	foreach ($stationhash as $stationname) {
 		print_r($item[$l]["$stationname"]);
 	}
 	print "</tr>\n";
