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