Blame view

WADB.cls.php 2.84 KB
1ee0c7177   tom200e   first
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  <?php
  
  	class WADB
  	{
  		/* Database Host */
  		var $sDbHost;           
  		var $sDbName;           // Database Name
  		var $sDbUser;           // Database User
  		var $sDbPwd;            // Database Password
  		var $sDbDetail;         // Database Details
  		var $iNoOfRecords;      // Total No of Records
  		var $oQueryResult;      // Results of sql query
  		var $aSelectRecords;    // Array
  		var $aArrRec;           // Array
  		var $bInsertRecords;    // Boolean
  		var $iInsertRecId;      // Integer - the primary key for inserted record
  		var $bUpdateRecords;    // Boolean
  		
  		/* Constructor */
  		function WADB ($sDbHost, $sDbName, $sDbUser, $sDbPwd)
  		{
  			$oDbLink = mysql_connect ($sDbHost, $sDbUser, $sDbPwd) or die ("MySQL DB could not be connected");
  			@mysql_select_db ($sDbName, $oDbLink)or die ("MySQL DB could not be selected");
  			@mysql_query("set names 'utf8'");
  		}
  		
  		/* seelct Record Object */
  		function selectRecordsObject($sSqlQuery){
  			unset($this->aSelectRecords);
  			$this->oQueryResult = mysql_query($sSqlQuery) or die(mysql_error());
  			$this->iNoOfRecords = mysql_num_rows($this->oQueryResult);
  			if ($this->iNoOfRecords > 0) {
  				while($obj = mysql_fetch_object($this->oQueryResult)) {
  					$this->aSelectRecords[] = $obj;
  				}	
  				mysql_free_result($this->oQueryResult);				
  			}						
  			$this->aArrRec = $this->aSelectRecords;
  			return $this->aArrRec;	
  		}
  
  		
  	    /* Select Records */
  		function selectRecords ($sSqlQuery)
  		{
  			unset($this->aSelectRecords);
  			$this->oQueryResult = mysql_query($sSqlQuery) or die(mysql_error());
  			$this->iNoOfRecords = mysql_num_rows($this->oQueryResult);
  			if ($this->iNoOfRecords > 0) {
  				while ($oRow = mysql_fetch_array($this->oQueryResult,MYSQL_ASSOC)) {
  					$this->aSelectRecords[] = $oRow;
  				}
  				mysql_free_result($this->oQueryResult);
  			}
  			$this->aArrRec = $this->aSelectRecords;
  			return $this->aArrRec;
  		}
  	
  		/*Get Number of Records */
  		function getNumberOfRecords () {
  			return $this->iNoOfRecords;
  		}
  	
  		/* Get selected data */
  		function getSelectedData (){
  			return $this->aSelectRecords;
  		}
  	
  		/* Insert Records */
  		function insertRecords($sSqlQuery)
  		{
  			$this->bInsertRecords = mysql_query ($sSqlQuery) or die (mysql_error());
  			$this->iInsertRecId = mysql_insert_id();
  			return $this->iInsertRecId;
  		}
  	
  		/* Find Inserted Id */
  		function getIdForInsertedRecord()
  		{
  			return $this->iInsertRecId;
  		}
  	
  		/* Update Records */
  		function updateRecords($sSqlQuery)
  		{
  			return mysql_query($sSqlQuery) or die(mysql_error());
  		}
  		function deleteRecords($sSqlQuery)
  		{
  			return mysql_query($sSqlQuery) or die(mysql_error());
  		}
  		/* 測試新增用 */
  		function insertUser($sSqlQuery)
  		{
  			return mysql_query($sSqlQuery) or die(mysql_error());
  		}
  		
  		/* 建立資料表 */
  		function creatTable($sSqlQuery)
  		{
  			return mysql_query($sSqlQuery) or die(mysql_error());
  		}
  		
  		
  	}
  ?>