Back to index

php5  5.3.10
conn_attr.inc
Go to the documentation of this file.
00001 <?php
00002 
00003 require(dirname(__FILE__)."/connect.inc");
00004 
00005 $sv = oci_server_version($c);
00006 $sv = preg_match('/Release (11\.2|12)\./', $sv, $matches);
00007 if ($sv == 1) {
00008     // Server is Oracle 11.2+
00009     $stmtarray = array(
00010         "drop user testuser cascade",
00011         "create user testuser identified by testuser",
00012         "grant connect,resource,dba to testuser",
00013         "alter user testuser enable editions",
00014         "drop edition myedition1",
00015         "drop edition myedition",
00016         "grant create any edition to testuser",
00017         "create edition myedition",
00018         "create edition myedition1 as child of myedition",
00019         "grant use on edition myedition to testuser",
00020         "grant use on edition myedition1 to testuser",
00021     );
00022 }
00023 else {
00024     // Server is Pre 11.2 
00025     $stmtarray = array(
00026         "drop user testuser cascade",
00027         "create user testuser identified by testuser",
00028         "grant connect,resource,dba to testuser",
00029     );
00030 }
00031 
00032 foreach ($stmtarray as $stmt) {
00033     $s = oci_parse($c, $stmt);
00034     $r = @oci_execute($s);
00035        if (!$r) {
00036               $m = oci_error($s);
00037               if (!in_array($m['code'], array(   // ignore expected errors
00038                         942 // table or view does not exist
00039                      , 1918 // user does not exist 
00040                      , 2289 // sequence does not exist
00041                      , 4080 // trigger does not exist
00042                     , 38802 // edition does not exist
00043                 ))) {
00044                      echo "Error:" . $stmt . PHP_EOL . $m['message'] . PHP_EOL;
00045             if ($m['code'] == 38807) {
00046                 echo "You appear to already have an edition in use that prevents this PHP test from running.  Query DBA_EDITIONS to see existing editions.". PHP_EOL;
00047             }
00048             die;
00049               }
00050        }
00051 }
00052 
00053 function get_attr($conn,$attr)
00054 {
00055     $sel_stmt="select " .$attr. " from v\$session where sid = 
00056        (select sid from v\$session where audsid = 
00057        sys_context('userenv','sessionid')) order by 1";
00058     $s2 = oci_parse($conn,$sel_stmt);
00059     oci_execute($s2,OCI_DEFAULT);
00060     while (oci_fetch($s2)) {
00061         echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
00062     }
00063 }
00064 
00065 /* Pass $conn_type=1 for a connection with oci_connect() 
00066    Pass $conn_type=2 for ooci_pconnect 
00067    Default will give a oci_new_connect */
00068 
00069 function get_conn($conn_type)
00070 {
00071        $user = 'testuser';
00072        $password = 'testuser';
00073        $dbase = $GLOBALS['dbase'];
00074        switch($conn_type) {
00075         case 1:
00076             echo "Testing with oci_connect()\n";
00077             return(oci_connect($user,$password,$dbase));
00078             break;
00079         case 2:
00080             echo "Testing with oci_pconnect()\n";
00081             return(oci_pconnect($user,$password,$dbase));
00082             break;
00083         default:
00084             echo "Testing with oci_new_connect()\n";
00085             return(oci_new_connect($user,$password,$dbase));
00086             break;
00087        }
00088 }
00089 
00090 function set_attr($conn,$attr,$sufix)
00091 {
00092        if (!strcmp($attr,'MODULE')) 
00093               $r = oci_set_module_name($conn,'PHP TEST'.$sufix);
00094        else if (!strcmp($attr,'ACTION')) 
00095         $r = oci_set_action($conn,'TASK'.$sufix);
00096        else if (!strcmp($attr,'CLIENT_INFO')) 
00097         $r = oci_set_client_info($conn,'INFO1'.$sufix);
00098        else if (!strcmp($attr,'CLIENT_IDENTIFIER')) 
00099         $r = oci_set_client_identifier($conn,'ID00'.$sufix);
00100        else
00101               echo "Pass one of the above four attibutes!!!\n";
00102        if ($r) {
00103               echo "Value of $attr has been set successfully\n";
00104     }
00105     
00106        //Do a round-trip here
00107        oci_server_version($conn);
00108        return $r;    
00109 }
00110 
00111 function set_edit_attr($value)
00112 {
00113        $r = oci_set_edition($value);
00114     if ($r) {
00115               echo " The value of edition has been successfully set\n";
00116     }
00117        return $r;
00118 }
00119 
00120 function get_edit_attr ($conn) {
00121        $sel_stmt = "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual";
00122     $s2 = oci_parse($conn,$sel_stmt);
00123     oci_execute($s2,OCI_DEFAULT);
00124     while (oci_fetch($s2)) {
00125         echo "The value of current EDITION is ".oci_result($s2,1)."\n";
00126     }
00127 }
00128 
00129 function get_sys_attr($conn,$attr)
00130 {
00131        $sel_stmt="select " .$attr. " from v\$session where sid = 
00132        (select sid from v\$session where audsid = sys_context('userenv','sessionid')) order by 1";
00133     $s2 = oci_parse($conn,$sel_stmt);
00134     oci_execute($s2,OCI_DEFAULT);
00135     while (oci_fetch($s2)) {
00136         echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
00137     }
00138 }
00139 
00140 function clean_up($c) {
00141        $stmtarray = array(
00142         "drop user testuser cascade",
00143         "drop edition myedition1",
00144         "drop edition myedition",
00145        );
00146     
00147        foreach ($stmtarray as $stmt) {
00148         $s = oci_parse($c, $stmt);
00149         @oci_execute($s);
00150        }
00151 }