OSDN Git Service

modified: epgwakealarm.php 省電力少し修正
[epgrec/epgrec.git] / upgrade_2012_04_22.php
1 #!/usr/bin/php
2 <?php
3 $script_path = dirname( __FILE__ );
4 chdir( $script_path );
5 include_once($script_path . '/config.php');
6 include_once(INSTALL_PATH . '/Settings.class.php' );
7 include_once(INSTALL_PATH . '/DBRecord.class.php' );
8 include_once(INSTALL_PATH . '/tableStruct.inc.php' );
9
10 // mysqli::multi_queryは動作がいまいちなので使わない
11
12 function multi_query( $sqlstrs, $dbh ) {
13         $error = false;
14         
15         foreach( $sqlstrs as $sqlstr ) {
16                 $res = mysql_query( $sqlstr );
17                 if( $res === FALSE ) {
18                         echo "failed: ". $sqlstr . "\n";
19                         $error = true;
20                 }
21         }
22         return $error;
23 }
24
25 function column_exists( $tbl, $col, $dbh ) {
26         $sqlstr = "show fields from ".$tbl." where Field='".$col."'";
27         $res = mysql_query( $sqlstr, $dbh );
28         return mysql_num_rows($res);
29 }
30
31 function index_exists( $tbl, $idx, $dbh ) {
32         $sqlstr = "show index from ".$tbl." where Key_name='".$idx."'";
33         $res = mysql_query( $sqlstr, $dbh );
34         return mysql_num_rows($res);
35 }
36
37
38 $settings = Settings::factory();
39 $dbh = mysql_connect( $settings->db_host, $settings->db_user, $settings->db_pass );
40 if( $dbh !== FALSE ) {
41
42         $sqlstr = "use ".$settings->db_name;
43         mysql_query( $sqlstr );
44
45         $sqlstr = "set NAMES 'utf8'";
46         mysql_query( $sqlstr );
47         
48         // PROGRAM_TBL
49
50         // インデックス追加
51         $sqlstrs = array();
52         if( index_exists( $settings->tbl_prefix.PROGRAM_TBL, "program_disc_idx", $dbh ) ) {
53                 echo "program_disc_idxはすでに存在しているため作成しません\n";
54         }
55         else {
56                 array_push( $sqlstrs, "create index program_disc_idx on ".$settings->tbl_prefix.PROGRAM_TBL."  (program_disc);" );
57         }
58         if( multi_query( $sqlstrs, $dbh ) ) {
59                 echo "予約テーブルにインデックスが作成できません\n";
60         }
61 }
62 else
63         exit( "DBの接続に失敗\n" );
64 ?>