diff DBRecord.class.php @ 159:66eabfc1b118

revoke all whitespace modifications
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 31 Mar 2010 06:42:51 +0900
parents 49145003e6a3
children
line wrap: on
line diff
--- a/DBRecord.class.php	Wed Mar 31 06:16:04 2010 +0900
+++ b/DBRecord.class.php	Wed Mar 31 06:42:51 2010 +0900
@@ -5,18 +5,18 @@
 class DBRecord {
 	protected $table;
 	protected $settings;
-
+	
 	protected $dbh;
 	public $id;
-
+	
     function __construct( $table, $property = null, $value = null ) {
 		$this->settings = Settings::factory();
-
+		
 		$this->table = $this->settings->tbl_prefix.$table;
-
+		
 		$this->dbh = @mysql_connect( $this->settings->db_host , $this->settings->db_user, $this->settings->db_pass );
 		if( $this->dbh === FALSE ) throw new exception( "construct:データベースに接続できない" );
-
+		
 		$sqlstr = "use ".$this->settings->db_name;
 		$res = $this->__query($sqlstr);
 		if( $res === false ) throw new exception("construct: " . $sqlstr );
@@ -31,17 +31,17 @@
 			$sqlstr = "SELECT * FROM ".$this->table.
 			            " WHERE ".mysql_real_escape_string( $property ).
 			              "='".mysql_real_escape_string( $value )."'";
-
+			
 			$res = $this->__query( $sqlstr );
 			$arr = mysql_fetch_array( $res , MYSQL_ASSOC );
 			if( $arr === FALSE ) throw new exception( "construct:無効な行" );
 			// 最初にヒットした行のidを使用する
 			$this->id = $arr['id'];
 		}
-
+		
 		return;
 	}
-
+	
 	function createTable( $tblstring ) {
 		$sqlstr = "use ".$this->settings->db_name;
 		$res = $this->__query($sqlstr);
@@ -50,20 +50,20 @@
 		$result = $this->__query( $sqlstr );
 		if( $result === false ) throw new exception( "createTable:テーブル作成失敗" );
 	}
-
+	
 	protected function __query( $sqlstr ) {
 		$res = @mysql_query( $sqlstr, $this->dbh );
 		if( $res === FALSE ) throw new exception( "__query:DBクエリ失敗:".$sqlstr );
 		return $res;
 	}
-
+	
 	function fetch_array( $property , $value, $options = null ) {
 		$retval = array();
-
+		
 		$sqlstr = "SELECT * FROM ".$this->table.
 		            " WHERE ".mysql_real_escape_string( $property ).
 		              "='".mysql_real_escape_string( $value )."'";
-
+		
 		if( $options != null ) {
 			$sqlstr .= "AND ".$options;
 		}
@@ -71,10 +71,10 @@
 		while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
 			array_push( $retval, $row );
 		}
-
+		
 		return $retval;
 	}
-
+	
 	function __set( $property, $value ) {
 		if( $property == "id" ) throw new exception( "set:idの変更は不可" );
 		// id = 0なら空の新規レコード作成
@@ -89,27 +89,27 @@
 		$res = $this->__query( $sqlstr );
 		if( $res == FALSE )  throw new exception("set:セット失敗" );
 	}
-
+	
 	function __get( $property ) {
 		if( $this->id == 0 ) throw new exception( "get:無効なid" );
 		if( $property == "id" ) return $this->id;
-
+		
 		$sqlstr = "SELECT ".mysql_real_escape_string($property)." FROM ".$this->table." WHERE id='".$this->id."'";
 		$res = $this->__query($sqlstr);
 		$arr = mysql_fetch_row( $res );
 		if( $arr === FALSE ) throw new exception( "get:".$property."は存在しない" );
-
+		
 		return stripslashes($arr[0]);
 	}
-
+	
 	function delete() {
 		if( $this->id == 0 ) throw new exception( "delete:無効なid" );
-
+		
 		$sqlstr = "DELETE FROM ".$this->table." WHERE id='".$this->id."'";
 		$this->__query( $sqlstr );
 		$this->id = 0;
 	}
-
+	
 	// countを実行する
 	static function countRecords( $table, $options = "" ) {
 		try{
@@ -124,7 +124,7 @@
 		$retval = mysql_fetch_row( $result );
 		return $retval[0];
 	}
-
+	
 	// DBRecordオブジェクトを返すstaticなメソッド
 	static function createRecords( $table, $options = "" ) {
 		$retval = array();
@@ -143,9 +143,9 @@
 		}
 		return $retval;
 	}
-
+	
 	function __destruct() {
 		$this->id = 0;
 	}
 }
-?>
+?>
\ No newline at end of file