/!PHP/???/oracle.php
PHP | 315 lines | 140 code | 57 blank | 118 comment | 10 complexity | 29099665637e6b8fc2ec580ecc05e7cc MD5 | raw file
- <?php
- /**
- * Oracle??????????PHP5
- *
- * @version 2010-7-8 14:05:02
- * @author Zerolone
- $db_conn = ocilogon ( "scott", "tiger", "CentOS/Zerolone", 'UTF8' );
- $cmdstr = "select * from xue_sheng";
- $parsed = ociparse ( $db_conn, $cmdstr );
- ociexecute ( $parsed );
- $nrows = ocifetchstatement ( $parsed, $results );
- echo "Oracle PHP Test";
- echo "<br /> <br />";
- echo " Name <br /> Salary <br /> <br />";
- for($i = 0; $i < $nrows; $i ++) {
- echo "<br />";
- echo "id=" . $results ["ID"] [$i] . "<br />";
- echo "name=" . $results ["XING_MING"] [$i] . " ";
- // echo " $ " . number_format($results["id"][$i], 2). " ";
- echo " <br />";
- }
-
- echo "Number of Rows: $nrows <br />";
- echo "If you see data, then it works!<br />";
- echo $_SERVER["HTTP_HOST"];
- */
-
- //class Db_MySQL{
- class Database {
- //????
- protected $ResID;
-
- //????
- public $SqlStr = '';
-
- //????
- public $ResultArr = '';
-
- //????
- public $QueryCount = 0;
-
- //????
- public $QueryStr = '';
-
- //????
- public $RecordCount = 0;
-
- //??
- public $PageNum = 1;
-
- //???
- public $PageSize = 16;
-
- //???
- public $Thispage = '';
-
- /**
- * ?????
- *
- */
- public function __construct() {
- //??????
- if (!$this->ResID = oci_connect ( DB_USER, DB_PASS, DB_HOST, DB_LANG )){
- $this->error_alert ( '?????', DB_HOST, '?????????' );
- }
- }
-
- /**
- * ??????
- * @param TableName ?? ????????????????????/include/config.inc.php???????
- * @param ArrField ???? ??????????
- * @param ArrValue ???? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- public function Insert($TableName, $ArrField, $ArrValue) {
- $SqlL = 'INSERT INTO ' . DB_TABLE_PRE . $TableName . ' (';
- $SqlR = 'values (';
-
- //????
- $CountArr = count ( $ArrField );
-
- for($i = 0; $i < $CountArr - 1; $i ++) {
- $SqlL .= $ArrField [$i] . ',';
- $SqlR .= ':'. $i . ',';
- }
-
- $SqlL .= $ArrField [$i] . ')';
- $SqlR .= ':' . $i . ')';
-
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
- $this->QueryStr .= $SqlL . $SqlR . "\n";
-
- $this->SqlStr= $SqlL . $SqlR ;
-
- DebugStr($this->SqlStr);
-
- $update = oci_parse ( $this->ResID, $this->SqlStr );
-
- for($i = 0; $i < $CountArr; $i ++) {
- oci_bind_by_name($update, ":$i", $ArrValue [$i], -1);
- }
-
- return oci_execute ($update);
-
-
- // return mysql_query ( $SqlL . $SqlR );
- }
-
- /**
- * ???????id??
- *
- * @return id
- */
- public function Insert_id() {
- return mysql_insert_id ( $this->ResID );
- }
-
- /**
- * ?????????
- * @param TableName ?? ?????????????????
- * @param ArrField ???? ??????????
- * @param ArrValue ???? ??????????
- * @param WhereStr ???? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- public function Update($TableName, $ArrField, $ArrValue, $WhereStr) {
- $SqlL = 'UPDATE ' . DB_TABLE_PRE . $TableName . ' SET ';
-
- //????
- $CountArr = count ( $ArrField );
-
- for($i = 0; $i < $CountArr - 1; $i ++) {
- // $SqlL .= $ArrField [$i] . '=';
- // $SqlL .= '\'' . $ArrValue [$i] . '\',';
-
- $SqlL .= $ArrField [$i] . '=:' . $i. ',' ;
- }
-
- $SqlL .= $ArrField [$i] . '=:';
- $SqlL .= $i;
-
- //WHERE??
- $SqlL .= ' WHERE ' . $WhereStr ;
-
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
- $this->QueryStr .= $SqlL . "\n";
-
- $this->SqlStr=$SqlL;
-
- // DebugStr($SqlL);
-
- $update = oci_parse ( $this->ResID, $this->SqlStr );
-
- for($i = 0; $i < $CountArr; $i ++) {
- oci_bind_by_name($update, ":$i", $ArrValue [$i], -1);
- }
-
- return oci_execute ($update);
- }
-
- /**
- * ?????????
- * @version 2008?11?13?15:15:52
- * @param TableName ?? ??????????
- * @param WhereStr ???? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- public function Delete($TableName, $WhereStr) {
- $SqlL = 'DELETE FROM `' . DB_TABLE_PRE . $TableName . '` WHERE ' . $WhereStr . ';';
-
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
- $this->QueryStr .= $SqlL . "\n";
- $this->SqlStr = $SqlL;
-
- return mysql_query ( $SqlL );
- }
-
- /**
- * ??Sql????? ????
- * @version 2008?11?13?11:55:59
- * @param SqlStr SQL?? ??????????
- *
- */
- public function Query() {
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
- $this->QueryStr .= $this->SqlStr . "\n";
-
- // DebugStr($this->SqlStr);
-
- //??Sql??
- $statement = oci_parse ( $this->ResID, $this->SqlStr );
- oci_execute ($statement);
-
- //??????
- unset ( $this->ResultArr );
- $return_int=0;
-
- //??????
- while ( $row = oci_fetch_array ( $statement, OCI_BOTH ) ) {
- // print_r($row);echo '<hr>';
- $this->ResultArr [] = $row;
- $return_int=1;
- }
-
- if ($return_int) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
-
- /**
- * ??????
- *
- * @return ???
- */
- public function version() {
- return mysql_get_server_info ( $this->ResID );
- }
-
- /**
- * ??SQL? ??
- * @version 2008?11?13?14:04:40
- * @param SqlStr SQL?? ??????????
- *
- * @return 0??1? 0 ???? 1???
- */
- public function ExecuteQuery() {
- //??
- $this->QueryCount ++;
- $this->QueryStr .= '--' . $this->QueryCount . '--' . "\n";
- $this->QueryStr .= $this->SqlStr . "\n";
-
- //??Sql??
- return mysql_query ( $this->SqlStr, $this->ResID );
- }
-
- /**
- * ??????
- */
- public function PrintDebug() {
- $variable_count = '--?????' . $this->QueryCount . "\n";
- $variable_sql = $this->QueryStr . "\n";
-
- $this->Thispage=$_SERVER ['PHP_SELF'];
-
- //??????
- $variable_log = "?????_GET???:\n" . print_array ( $_GET );
- $variable_log .= "?????_POST???:\n" . print_array ( $_POST );
- $variable_log .= "?????_COOKIE???:\n" . print_array ( $_COOKIE );
- $variable_log .= "?????_SESSION???:\n" . print_array ( @$_SESSION );
-
- //IIS???? ????????????
- //$variable_log .= "HTTP???:\n" . print_array ( getallheaders () );
-
- return "$this->Thispage [<a href=\"javascript:history.go(0);\">??</a>]
- <script language=\"javascript\" type=\"text/javascript\">
- function showdebug(span_show, span_source)
- {
- var TheImg;
- span_show = eval(span_show);
- span_source = eval(span_source)
-
- if(span_show.style.display == \"none\")
- {
- span_show.style.display = \"\";
- span_source.innerHTML = \"<font color='blue'>??</font>????\";
- }
- else
- {
- span_show.style.display = \"none\";
- span_source.innerHTML = \"<font color='red'>??</font>????\";
- }
- }
- </script>
- <span align=left id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"red\">??</font>????</span><br>
- <!-- <span id=debug_source onClick=showdebug('debug_show','debug_source')><font color=\"blue\">??</font>????</span><br> -->
- <div align=\"left\"><span id=debug_show style=\"display=none\">
- <textarea style='width=800;height=500' cols='100' rows='8'>$variable_count$variable_sql$variable_log</textarea>
- </span>
- </div>
- ";
- }
-
- /**
- * ????
- * @param $ImagePath ????
- * @param $ImageUrl ?
- * @param String ????
- */
- function error_alert($Type, $Source, $Message) {
- $ThisPage = $_SERVER ['PHP_SELF'];
-
- $x = "
- ?????????<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>
- <br>????? ($Source) $Message
- <hr color=blue size=1 width=100% align=left>
- ";
- echo $x;
- }
-
- }
-
- ?>