3 $script_path = dirname( __FILE__ );
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' );
10 // mysqli::multi_queryは動作がいまいちなので使わない
12 function multi_query( $sqlstrs, $dbh ) {
15 foreach( $sqlstrs as $sqlstr ) {
16 $res = mysql_query( $sqlstr );
17 if( $res === FALSE ) {
18 echo "failed: ". $sqlstr . "\n";
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);
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);
38 $settings = Settings::factory();
39 $dbh = mysql_connect( $settings->db_host, $settings->db_user, $settings->db_pass );
40 if( $dbh !== FALSE ) {
42 $sqlstr = "use ".$settings->db_name;
43 mysql_query( $sqlstr );
45 $sqlstr = "set NAMES 'utf8'";
46 mysql_query( $sqlstr );
52 if( index_exists( $settings->tbl_prefix.PROGRAM_TBL, "program_disc_idx", $dbh ) ) {
53 echo "program_disc_idxはすでに存在しているため作成しません\n";
56 array_push( $sqlstrs, "create index program_disc_idx on ".$settings->tbl_prefix.PROGRAM_TBL." (program_disc);" );
58 if( multi_query( $sqlstrs, $dbh ) ) {
59 echo "予約テーブルにインデックスが作成できません\n";