comparison DBRecord.class.php @ 32:01a8fdc0cebb

testing: Web base setting page.
author Sushi-k <epgrec@park.mda.or.jp>
date Mon, 27 Jul 2009 18:48:51 +0900
parents d3ee3927eb3a
children e5f9aa34d06f
comparison
equal deleted inserted replaced
31:6bb8f29c80c0 32:01a8fdc0cebb
1 <?php 1 <?php
2 include_once( 'config.php' ); 2 include_once( 'config.php' );
3 include_once( 'Settings.class.php' );
3 4
4 class DBRecord { 5 class DBRecord {
5 protected $table; 6 protected $table;
6 7
7 protected $dbh; 8 protected $dbh;
8 public $id; 9 public $id;
9 10
10 function __construct( $table, $property = null, $value = null ) { 11 function __construct( $table, $property = null, $value = null ) {
12 $settings = Settings::factory();
13
11 $this->table = $table; 14 $this->table = $table;
12 15
13 $this->dbh = @mysql_connect( DB_HOST, DB_USER, DB_PASS ); 16 $this->dbh = @mysql_connect( $settings->db_host , $settings->db_user, $settings->db_pass );
14 if( $this->dbh === FALSE ) throw new exception( "construct:データベースに接続できない" ); 17 if( $this->dbh === FALSE ) throw new exception( "construct:データベースに接続できない" );
15 18
16 $sqlstr = "use ".DB_NAME; 19 $sqlstr = "use ".$settings->db_name;
17 $res = $this->__query($sqlstr); 20 $res = $this->__query($sqlstr);
18 if( $res === false ) throw new exception("construct: " . $sqlstr ); 21 if( $res === false ) throw new exception("construct: " . $sqlstr );
19 $sqlstr = "set NAMES utf8"; 22 $sqlstr = "set NAMES utf8";
20 $res = $this->__query($sqlstr); 23 $res = $this->__query($sqlstr);
21 24
37 40
38 return; 41 return;
39 } 42 }
40 43
41 function createTable( $tblstring ) { 44 function createTable( $tblstring ) {
42 $sqlstr = "use ".DB_NAME; 45 $settings = Settings::factory();
46
47 $sqlstr = "use ".$settings->db_name;
43 $res = $this->__query($sqlstr); 48 $res = $this->__query($sqlstr);
44 if( $res === false ) throw new exception("createTable: " . $sqlstr ); 49 if( $res === false ) throw new exception("createTable: " . $sqlstr );
45 $sqlstr = "CREATE TABLE IF NOT EXISTS ".$this->table." (" .$tblstring.") DEFAULT CHARACTER SET 'utf8'"; 50 $sqlstr = "CREATE TABLE IF NOT EXISTS ".$this->table." (" .$tblstring.") DEFAULT CHARACTER SET 'utf8'";
46 $result = $this->__query( $sqlstr ); 51 $result = $this->__query( $sqlstr );
47 if( $result === false ) throw new exception( "createTable:テーブル作成失敗" ); 52 if( $result === false ) throw new exception( "createTable:テーブル作成失敗" );