PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/!PHP/???/oracle.php

http://mootoolstools.googlecode.com/
PHP | 315 lines | 140 code | 57 blank | 118 comment | 10 complexity | 29099665637e6b8fc2ec580ecc05e7cc MD5 | raw file
  1. <?php
  2. /**
  3. * Oracle??????????PHP5
  4. *
  5. * @version 2010-7-8 14:05:02
  6. * @author Zerolone
  7. $db_conn = ocilogon ( "scott", "tiger", "CentOS/Zerolone", 'UTF8' );
  8. $cmdstr = "select * from xue_sheng";
  9. $parsed = ociparse ( $db_conn, $cmdstr );
  10. ociexecute ( $parsed );
  11. $nrows = ocifetchstatement ( $parsed, $results );
  12. echo "Oracle PHP Test";
  13. echo "<br /> <br />";
  14. echo " Name <br /> Salary <br /> <br />";
  15. for($i = 0; $i < $nrows; $i ++) {
  16. echo "<br />";
  17. echo "id=" . $results ["ID"] [$i] . "<br />";
  18. echo "name=" . $results ["XING_MING"] [$i] . " ";
  19. // echo " $ " . number_format($results["id"][$i], 2). " ";
  20. echo " <br />";
  21. }
  22. echo "Number of Rows: $nrows <br />";
  23. echo "If you see data, then it works!<br />";
  24. echo $_SERVER["HTTP_HOST"];
  25. */
  26. //class Db_MySQL{
  27. class Database {
  28. //????
  29. protected $ResID;
  30. //????
  31. public $SqlStr = '';
  32. //????
  33. public $ResultArr = '';
  34. //????
  35. public $QueryCount = 0;
  36. //????
  37. public $QueryStr = '';
  38. //????
  39. public $RecordCount = 0;
  40. //??
  41. public $PageNum = 1;
  42. //???
  43. public $PageSize = 16;
  44. //???
  45. public $Thispage = '';
  46. /**
  47. * ?????
  48. *
  49. */
  50. public function __construct() {
  51. //??????
  52. if (!$this->ResID = oci_connect ( DB_USER, DB_PASS, DB_HOST, DB_LANG )){
  53. $this->error_alert ( '?????', DB_HOST, '?????????' );
  54. }
  55. }
  56. /**
  57. * ??????
  58. * @param TableName ?? ????????????????????/include/config.inc.php???????
  59. * @param ArrField ???? ??????????
  60. * @param ArrValue ???? ??????????
  61. *
  62. * @return 0??1? 0 ???? 1???
  63. */
  64. public function Insert($TableName, $ArrField, $ArrValue) {
  65. $SqlL = 'INSERT INTO ' . DB_TABLE_PRE . $TableName . ' (';
  66. $SqlR = 'values (';
  67. //????
  68. $CountArr = count ( $ArrField );
  69. for($i = 0; $i < $CountArr - 1; $i ++) {
  70. $SqlL .= $ArrField [$i] . ',';
  71. $SqlR .= ':'. $i . ',';
  72. }
  73. $SqlL .= $ArrField [$i] . ')';
  74. $SqlR .= ':' . $i . ')';
  75. //??
  76. $this->QueryCount ++;
  77. $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
  78. $this->QueryStr .= $SqlL . $SqlR . "\n";
  79. $this->SqlStr= $SqlL . $SqlR ;
  80. DebugStr($this->SqlStr);
  81. $update = oci_parse ( $this->ResID, $this->SqlStr );
  82. for($i = 0; $i < $CountArr; $i ++) {
  83. oci_bind_by_name($update, ":$i", $ArrValue [$i], -1);
  84. }
  85. return oci_execute ($update);
  86. // return mysql_query ( $SqlL . $SqlR );
  87. }
  88. /**
  89. * ???????id??
  90. *
  91. * @return id
  92. */
  93. public function Insert_id() {
  94. return mysql_insert_id ( $this->ResID );
  95. }
  96. /**
  97. * ?????????
  98. * @param TableName ?? ?????????????????
  99. * @param ArrField ???? ??????????
  100. * @param ArrValue ???? ??????????
  101. * @param WhereStr ???? ??????????
  102. *
  103. * @return 0??1? 0 ???? 1???
  104. */
  105. public function Update($TableName, $ArrField, $ArrValue, $WhereStr) {
  106. $SqlL = 'UPDATE ' . DB_TABLE_PRE . $TableName . ' SET ';
  107. //????
  108. $CountArr = count ( $ArrField );
  109. for($i = 0; $i < $CountArr - 1; $i ++) {
  110. // $SqlL .= $ArrField [$i] . '=';
  111. // $SqlL .= '\'' . $ArrValue [$i] . '\',';
  112. $SqlL .= $ArrField [$i] . '=:' . $i. ',' ;
  113. }
  114. $SqlL .= $ArrField [$i] . '=:';
  115. $SqlL .= $i;
  116. //WHERE??
  117. $SqlL .= ' WHERE ' . $WhereStr ;
  118. //??
  119. $this->QueryCount ++;
  120. $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
  121. $this->QueryStr .= $SqlL . "\n";
  122. $this->SqlStr=$SqlL;
  123. // DebugStr($SqlL);
  124. $update = oci_parse ( $this->ResID, $this->SqlStr );
  125. for($i = 0; $i < $CountArr; $i ++) {
  126. oci_bind_by_name($update, ":$i", $ArrValue [$i], -1);
  127. }
  128. return oci_execute ($update);
  129. }
  130. /**
  131. * ?????????
  132. * @version 2008?11?13?15:15:52
  133. * @param TableName ?? ??????????
  134. * @param WhereStr ???? ??????????
  135. *
  136. * @return 0??1? 0 ???? 1???
  137. */
  138. public function Delete($TableName, $WhereStr) {
  139. $SqlL = 'DELETE FROM `' . DB_TABLE_PRE . $TableName . '` WHERE ' . $WhereStr . ';';
  140. //??
  141. $this->QueryCount ++;
  142. $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
  143. $this->QueryStr .= $SqlL . "\n";
  144. $this->SqlStr = $SqlL;
  145. return mysql_query ( $SqlL );
  146. }
  147. /**
  148. * ??Sql????? ????
  149. * @version 2008?11?13?11:55:59
  150. * @param SqlStr SQL?? ??????????
  151. *
  152. */
  153. public function Query() {
  154. //??
  155. $this->QueryCount ++;
  156. $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
  157. $this->QueryStr .= $this->SqlStr . "\n";
  158. // DebugStr($this->SqlStr);
  159. //??Sql??
  160. $statement = oci_parse ( $this->ResID, $this->SqlStr );
  161. oci_execute ($statement);
  162. //??????
  163. unset ( $this->ResultArr );
  164. $return_int=0;
  165. //??????
  166. while ( $row = oci_fetch_array ( $statement, OCI_BOTH ) ) {
  167. // print_r($row);echo '<hr>';
  168. $this->ResultArr [] = $row;
  169. $return_int=1;
  170. }
  171. if ($return_int) {
  172. return TRUE;
  173. } else {
  174. return FALSE;
  175. }
  176. }
  177. /**
  178. * ??????
  179. *
  180. * @return ???
  181. */
  182. public function version() {
  183. return mysql_get_server_info ( $this->ResID );
  184. }
  185. /**
  186. * ??SQL? ??
  187. * @version 2008?11?13?14:04:40
  188. * @param SqlStr SQL?? ??????????
  189. *
  190. * @return 0??1? 0 ???? 1???
  191. */
  192. public function ExecuteQuery() {
  193. //??
  194. $this->QueryCount ++;
  195. $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
  196. $this->QueryStr .= $this->SqlStr . "\n";
  197. //??Sql??
  198. return mysql_query ( $this->SqlStr, $this->ResID );
  199. }
  200. /**
  201. * ??????
  202. */
  203. public function PrintDebug() {
  204. $variable_count = '--?????' . $this->QueryCount . "\n";
  205. $variable_sql = $this->QueryStr . "\n";
  206. $this->Thispage=$_SERVER ['PHP_SELF'];
  207. //??????
  208. $variable_log = "?????_GET???:\n" . print_array ( $_GET );
  209. $variable_log .= "?????_POST???:\n" . print_array ( $_POST );
  210. $variable_log .= "?????_COOKIE???:\n" . print_array ( $_COOKIE );
  211. $variable_log .= "?????_SESSION???:\n" . print_array ( @$_SESSION );
  212. //IIS???? ????????????
  213. //$variable_log .= "HTTP???:\n" . print_array ( getallheaders () );
  214. return "$this->Thispage [<a href=\"javascript:history.go(0);\">??</a>]
  215. <script language=\"javascript\" type=\"text/javascript\">
  216. function showdebug(span_show, span_source)
  217. {
  218. var TheImg;
  219. span_show = eval(span_show);
  220. span_source = eval(span_source)
  221. if(span_show.style.display == \"none\")
  222. {
  223. span_show.style.display = \"\";
  224. span_source.innerHTML = \"<font color='blue'>??</font>????\";
  225. }
  226. else
  227. {
  228. span_show.style.display = \"none\";
  229. span_source.innerHTML = \"<font color='red'>??</font>????\";
  230. }
  231. }
  232. </script>
  233. <span align=left id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"red\">??</font>????</span><br>
  234. <!-- <span id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"blue\">??</font>????</span><br> -->
  235. <div align=\"left\"><span id=debug_show style=\"display=none\">
  236. <textarea style='width=800;height=500' cols='100' rows='8'>$variable_count$variable_sql$variable_log</textarea>
  237. </span>
  238. </div>
  239. ";
  240. }
  241. /**
  242. * ????
  243. * @param $ImagePath ????
  244. * @param $ImageUrl ?
  245. * @param String ????
  246. */
  247. function error_alert($Type, $Source, $Message) {
  248. $ThisPage = $_SERVER ['PHP_SELF'];
  249. $x = "
  250. ?????????<font color=red>$Type</font>?<a href=\"javascript:history.go(0);\">?????</a>??<a href=\"report_error_page.php?Page=$ThisPage&Source=$Source&Message=$Message\" target=_blank>??????? ??????????</a>?<br>
  251. <br>????? ($Source) $Message
  252. <hr color=blue size=1 width=100% align=left>
  253. ";
  254. echo $x;
  255. }
  256. }
  257. ?>