comparison DBRecord.class.php @ 39:8965ef108821

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