<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EaseMarry Blogs &#187; Oracle</title>
	<atom:link href="http://www.easemarry.com/blog/category/database/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.easemarry.com/blog</link>
	<description>php and java code</description>
	<lastBuildDate>Sun, 09 Aug 2009 16:09:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Oracle class &#8211; PHP</title>
		<link>http://www.easemarry.com/blog/oracle-class-php/</link>
		<comments>http://www.easemarry.com/blog/oracle-class-php/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 11:51:17 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Completeness]]></category>
		<category><![CDATA[Constructor Function]]></category>
		<category><![CDATA[Oracle 9i]]></category>
		<category><![CDATA[Oracle Class]]></category>
		<category><![CDATA[Oracle Home]]></category>
		<category><![CDATA[Php Class]]></category>
		<category><![CDATA[Putenv]]></category>
		<category><![CDATA[Sid]]></category>
		<category><![CDATA[Strange Error]]></category>
		<category><![CDATA[Zombie]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/?p=6</guid>
		<description><![CDATA[&#60;?php
class DB_Sql {
 var $Debug = false;
 var $Home = &#8220;/u01/app/oracle/ora90&#8243;;
 var $Remote = 1;
 /**
  * http://www.easemarry.com/blog
  * This Query will be sent directly after the first connection
  * Example:
  * var $ConnectQuery=&#8221;ALTER SESSION SET nls_date_language=german nls_date_format=&#8217;DD.MM.RRRR&#8217;&#8221;;
  * -&#62; Set the date format for this session, this is fine when your ora-role
  * cannot be altered
  */
 var $ConnectQuery=&#8221;;
 /**
  [...]]]></description>
			<content:encoded><![CDATA[<p>&lt;?php<br />
class DB_Sql {<br />
 var $Debug = false;<br />
 var $Home = &#8220;/u01/app/oracle/ora90&#8243;;<br />
 var $Remote = 1;<br />
 /**<br />
  * <a href="http://www.easemarry.com/blog">http://www.easemarry.com/blog</a><br />
  * This Query will be sent directly after the first connection<br />
  * Example:<br />
  * var $ConnectQuery=&#8221;ALTER SESSION SET nls_date_language=german nls_date_format=&#8217;DD.MM.RRRR&#8217;&#8221;;<br />
  * -&gt; Set the date format for this session, this is fine when your ora-role<br />
  * cannot be altered<br />
  */<br />
 var $ConnectQuery=&#8221;;<br />
 /**<br />
  * Due to a strange error with Oracle 9i, Apache and PHP4<br />
  * you don&#8217;t need to set the ENV &#8211; on my system Apache will change to a zombie, if I don&#8217;t set this to FALSE!<br />
  * Instead I set these ENV-vars before the startup of apache.<br />
  * If unsure try it out, if it works.�<br />
 .*/<br />
 var $OraPutEnv = true;</p>
<p> var $Database = &#8220;&#8221;;<br />
 var $User = &#8220;&#8221;;<br />
 var $Password = &#8220;&#8221;;</p>
<p> var $Link_ID = 0;<br />
 var $Query_ID = 0;<br />
 var $Record = array();<br />
 var $Row;</p>
<p> var $Errno = 0;<br />
 var $Error = &#8220;&#8221;;<br />
 var $ora_no_next_fetch=false;<br />
 /* copied from db_mysql for completeness */<br />
 /* public: identification constant. never change this. */<br />
 var $type = &#8220;oracle&#8221;;<br />
 var $revision = &#8220;Revision: 1.3&#8243;;<br />
 var $Halt_On_Error = &#8220;yes&#8221;; ## &#8220;yes&#8221; (halt with message), &#8220;no&#8221; (ignore errors quietly), &#8220;report&#8221; (ignore errror, but spit a warning)</p>
<p> /* public: constructor */<br />
 function DB_Sql($query = &#8220;&#8221;) {<br />
  $this-&gt;query($query);<br />
 }</p>
<p> /* public: some trivial reporting */<br />
 function link_id() {<br />
  return $this-&gt;Link_ID;<br />
 }</p>
<p> function query_id() {<br />
  return $this-&gt;Query_ID;<br />
 }</p>
<p> function connect() {<br />
  ## see above why we do this<br />
  if ($this-&gt;OraPutEnv) {<br />
   PutEnv(&#8221;ORACLE_SID=$this-&gt;Database&#8221;);<br />
   PutEnv(&#8221;ORACLE_HOME=$this-&gt;Home&#8221;);<br />
  }<br />
  if ( 0 == $this-&gt;Link_ID ) {<br />
   if($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;Connect()ing to $this-&gt;Database&#8230;&lt;br&gt;n&#8221;);<br />
   }<br />
   if($this-&gt;Remote) {<br />
    if($this-&gt;Debug) {<br />
     printf(&#8221;&lt;br&gt;connect() $this-&gt;User/******@$this-&gt;Database&lt;br&gt;n&#8221;);<br />
    }<br />
    $this-&gt;Link_ID=ora_plogon<br />
    (&#8221;$this-&gt;User/$this-&gt;Password@$this-&gt;Database&#8221;,&#8221;");<br />
    /************** (comment by SSilk)<br />
    this dosn&#8217;t work on my system:<br />
    $this-&gt;Link_ID=ora_plogon<br />
    (&#8221;$this-&gt;User@$this-&gt;Database.world&#8221;,&#8221;$this-&gt;Password&#8221;);<br />
    ***************/<br />
   } else {<br />
    if($this-&gt;Debug) {<br />
     printf(&#8221;&lt;br&gt;connect() $this-&gt;User, $this-&gt;Password &lt;br&gt;n&#8221;);<br />
    }<br />
    $this-&gt;Link_ID=ora_plogon(&#8221;$this-&gt;User&#8221;,&#8221;$this-&gt;Password&#8221;);<br />
    /* (comment by SSilk: don&#8217;t know how this could work, but I leave this untouched!) */<br />
   }<br />
   if($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;connect() Link_ID: $this-&gt;Link_ID&lt;br&gt;n&#8221;);<br />
   }<br />
   if (!$this-&gt;Link_ID) {<br />
    $this-&gt;halt(&#8221;connect() Link-ID == false &#8221; .<br />
    &#8221;($this-&gt;Link_ID), ora_plogon failed&#8221;);<br />
   } else {<br />
    //echo &#8220;commit on&lt;p&gt;&#8221;;<br />
    ora_commiton($this-&gt;Link_ID);<br />
   }<br />
   if($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;connect() Obtained the Link_ID: $this-&gt;Link_ID&lt;br&gt;n&#8221;);<br />
   }<br />
   ## Execute Connect Query<br />
   if ($this-&gt;ConnectQuery) {<br />
    $this-&gt;query($this-&gt;ConnectQuery);<br />
   }<br />
  }<br />
 }</p>
<p> ## In order to increase the # of cursors per system/user go edit the<br />
 ## init.ora file and increase the max_open_cursors parameter. Yours is on<br />
 ## the default value, 100 per user.<br />
 ## We tried to change the behaviour of query() in a way, that it tries<br />
 ## to safe cursors, but on the other side be carefull with this, that you<br />
 ## don&#8217;t use an old result.<br />
 ##<br />
 ## You can also make extensive use of -&gt;disconnect()!<br />
 ## The unused QueryIDs will be recycled sometimes.</p>
<p> function query($Query_String)<br />
 {</p>
<p>  /* No empty query please. */<br />
  if (empty($Query_String))<br />
  {<br />
   return 0;<br />
  }</p>
<p>  $this-&gt;connect();<br />
  $this-&gt;lastQuery=$Query_String;</p>
<p>  if (!$this-&gt;Query_ID) {<br />
   $this-&gt;Query_ID= ora_open($this-&gt;Link_ID);<br />
  }<br />
  if($this-&gt;Debug) {<br />
   printf(&#8221;Debug: query = %s&lt;br&gt;n&#8221;, $Query_String);<br />
   printf(&#8221;&lt;br&gt;Debug: Query_ID: %d&lt;br&gt;n&#8221;, $this-&gt;Query_ID);<br />
  }</p>
<p>  if(!@ora_parse($this-&gt;Query_ID,$Query_String)) {<br />
   $this-&gt;Errno=ora_errorcode($this-&gt;Query_ID);<br />
   $this-&gt;Error=ora_error($this-&gt;Query_ID);<br />
   $this-&gt;halt(&#8221;&lt;BR&gt;ora_parse() failed:&lt;BR&gt;$Query_String&lt;BR&gt;&lt;small&gt;Snap &amp; paste this to sqlplus!&lt;/SMALL&gt;&#8221;);<br />
  } elseif (!@ora_exec($this-&gt;Query_ID)) {<br />
   $this-&gt;Errno=ora_errorcode($this-&gt;Query_ID);<br />
   $this-&gt;Error=ora_error($this-&gt;Query_ID);<br />
   $this-&gt;halt(&#8221;&lt;BR&gt;n$Query_Stringn&lt;BR&gt;&lt;small&gt;Snap &amp; paste this to sqlplus!&lt;/SMALL&gt;&#8221;);<br />
  }</p>
<p>  $this-&gt;Row=0;</p>
<p>  if(!$this-&gt;Query_ID) {<br />
   $this-&gt;halt(&#8221;Invalid SQL: &#8220;.$Query_String);<br />
  }</p>
<p>  return $this-&gt;Query_ID;<br />
 }</p>
<p> function next_record() {<br />
  if (!$this-&gt;ora_no_next_fetch &amp;&amp;<br />
  0 == ora_fetch($this-&gt;Query_ID)) {<br />
   if ($this-&gt;Debug) {<br />
    printf(&#8221;&lt;br&gt;next_record(): ID: %d Row: %d&lt;br&gt;n&#8221;,<br />
    $this-&gt;Query_ID,$this-&gt;Row+1);<br />
    // more info for $this-&gt;Row+1 is $this-&gt;num_rows(),<br />
    // but dosn&#8217;t work in all cases (complicated selects)<br />
    // and it is very slow here<br />
   }<br />
   $this-&gt;Row +=1;</p>
<p>   $errno=ora_errorcode($this-&gt;Query_ID);<br />
   if(1403 == $errno) { # 1043 means no more records found<br />
    $this-&gt;Errno=0;<br />
    $this-&gt;Error=&#8221;";<br />
    $this-&gt;disconnect();<br />
    $stat=0;<br />
   } else {<br />
    $this-&gt;Error=ora_error($this-&gt;Query_ID);<br />
    $this-&gt;Errno=$errno;<br />
    if($this-&gt;Debug) {<br />
     printf(&#8221;&lt;br&gt;%d Error: %s&#8221;,<br />
     $this-&gt;Errno,<br />
     $this-&gt;Error);<br />
    }<br />
    $stat=0;<br />
   }<br />
  } else {<br />
   $this-&gt;ora_no_next_fetch=false;<br />
   for($ix=0;$ix&lt;ora_numcols($this-&gt;Query_ID);$ix++) {<br />
    $col=strtolower(ora_columnname($this-&gt;Query_ID,$ix));<br />
    $value=ora_getcolumn($this-&gt;Query_ID,$ix);<br />
    $this-&gt;Record[ "$col" ] = $value;<br />
    $this-&gt;Record[ $ix ] = $value;<br />
    #DBG echo&#8221;&lt;b&gt;[$col]&lt;/b&gt;: $value &lt;br&gt;n&#8221;;<br />
   }<br />
   $stat=1;<br />
  }</p>
<p>  return $stat;<br />
 }</p>
<p> ## seek() works only for $pos &#8211; 1 and $pos<br />
 ## Perhaps I make a own implementation, but my<br />
 ## opinion is, that this should be done by PHP3<br />
 function seek($pos) {<br />
  if ($this-&gt;Row &#8211; 1 == $pos) {<br />
   $this-&gt;ora_no_next_fetch=true;<br />
  } elseif ($this-&gt;Row == $pos ) {<br />
   ## do nothing<br />
  } else {<br />
   $this-&gt;halt(&#8221;Invalid seek(): Position is cannot be handled by API.&lt;BR&gt;&#8221;.<br />
   &#8221;Only a seek to the last element is allowed in this version&lt;BR&gt;&#8221;.<br />
   &#8221;Difference too big. Wanted: $pos Current pos: $this-&gt;Row&#8221;);<br />
  }<br />
  if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: seek = $pos&lt;BR&gt;&#8221;;<br />
  $this-&gt;Row=$pos;<br />
 }</p>
<p> function lock($table, $mode = &#8220;write&#8221;) {<br />
  if ($mode == &#8220;write&#8221;) {<br />
   $result = ora_do($this-&gt;Link_ID, &#8220;lock table $table in row exclusive mode&#8221;);<br />
  } else {<br />
   $result = 1;<br />
  }<br />
  return $result;<br />
 }</p>
<p> function unlock() {<br />
  return ora_do($this-&gt;Link_ID, &#8220;commit&#8221;);<br />
 }</p>
<p> // Important note: This function dosn&#8217;t work with Oracle-Database-Links!<br />
 // You are free to get a better method. :)<br />
 function metadata($table,$full=false) {<br />
  $count = 0;<br />
  $id = 0;<br />
  $res = array();</p>
<p>  /*<br />
  * Due to compatibility problems with Table we changed the behavior<br />
  * of metadata();<br />
  * depending on $full, metadata returns the following values:<br />
  *<br />
  * &#8211; full is false (default):<br />
  * $result[]:<br />
  * [0]["table"] table name<br />
  * [0]["name"] field name<br />
  * [0]["type"] field type<br />
  * [0]["len"] field length<br />
  * [0]["flags"] field flags (&#8221;NOT NULL&#8221;, &#8220;INDEX&#8221;)<br />
  * [0]["format"] precision and scale of number (eg. &#8220;10,2&#8243;) or empty<br />
  * [0]["index"] name of index (if has one)<br />
  * [0]["chars"] number of chars (if any char-type)<br />
  *<br />
  * &#8211; full is true<br />
  * $result[]:<br />
  * ["num_fields"] number of metadata records<br />
  * [0]["table"] table name<br />
  * [0]["name"] field name<br />
  * [0]["type"] field type<br />
  * [0]["len"] field length<br />
  * [0]["flags"] field flags (&#8221;NOT NULL&#8221;, &#8220;INDEX&#8221;)<br />
  * [0]["format"] precision and scale of number (eg. &#8220;10,2&#8243;) or empty<br />
  * [0]["index"] name of index (if has one)<br />
  * [0]["chars"] number of chars (if any char-type)<br />
  * [0]["php_type"] the correspondig PHP-type<br />
  * [0]["php_subtype"] the subtype of PHP-type<br />
  * ["meta"][field name] index of field named &#8220;field name&#8221;<br />
  * This could used, if you have the name, but no index-num &#8211; very fast<br />
  * Test: if (isset($result['meta']['myfield'])) {} &#8230;<br />
  */</p>
<p>  $this-&gt;connect();</p>
<p>  ## This is a RIGHT OUTER JOIN: &#8220;(+)&#8221;, if you want to see, what<br />
  ## this query results try the following:<br />
  ## $table = new Table; $db = new my_DB_Sql; # you have to make<br />
  ## # your own class<br />
  ## $table-&gt;show_results($db-&gt;query(see query vvvvvv))<br />
  ##<br />
  $this-&gt;query(&#8221;SELECT T.table_name,T.column_name,T.data_type,&#8221;.<br />
  &#8221;T.data_length,T.data_precision,T.data_scale,T.nullable,&#8221;.<br />
  &#8221;T.char_col_decl_length,I.index_name&#8221;.<br />
  &#8221; FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I&#8221;.<br />
  &#8221; WHERE T.column_name=I.column_name (+)&#8221;.<br />
  &#8221; AND T.table_name=I.table_name (+)&#8221;.<br />
  &#8221; AND T.table_name=UPPER(&#8217;$table&#8217;) ORDER BY T.column_id&#8221;);</p>
<p>  $i=0;<br />
  while ($this-&gt;next_record()) {<br />
   $res[$i]["table"] = $this-&gt;Record[table_name];<br />
   $res[$i]["name"] = strtolower($this-&gt;Record[column_name]);<br />
   $res[$i]["type"] = $this-&gt;Record[data_type];<br />
   $res[$i]["len"] = $this-&gt;Record[data_length];<br />
   if ($this-&gt;Record[index_name]) $res[$i]["flags"] = &#8220;INDEX &#8220;;<br />
   $res[$i]["flags"] .= ( $this-&gt;Record[nullable] == &#8216;N&#8217;) ? &#8221; : &#8216;NOT NULL&#8217;;<br />
   $res[$i]["format"]= (int)$this-&gt;Record[data_precision].&#8221;,&#8221;.<br />
   (int)$this-&gt;Record[data_scale];<br />
   if (&#8221;0,0&#8243;==$res[$i]["format"]) $res[$i]["format"]=&#8221;;<br />
   $res[$i]["index"] = $this-&gt;Record[index_name];<br />
   $res[$i]["chars"] = $this-&gt;Record[char_col_decl_length];<br />
   if ($full) {<br />
    $j=$res[$i]["name"];<br />
    $res["meta"][$j] = $i;<br />
    $res["meta"][strtoupper($j)] = $i;<br />
    switch ($res[$i]["type"]) {<br />
     case &#8220;VARCHAR2&#8243; :<br />
     case &#8220;VARCHAR&#8221; :<br />
     case &#8220;CHAR&#8221; :<br />
      $res["php_type"]=&#8221;string&#8221;;<br />
      $res["php_subtype"]=&#8221;";<br />
      break;<br />
     case &#8220;DATE&#8221; :<br />
      $res["php_type"]=&#8221;string&#8221;;<br />
      $res["php_subtype"]=&#8221;date&#8221;;<br />
      break;<br />
     case &#8220;BLOB&#8221; :<br />
     case &#8220;CLOB&#8221; :<br />
     case &#8220;BFILE&#8221; :<br />
     case &#8220;RAW&#8221; :<br />
     case &#8220;LONG&#8221; :<br />
     case &#8220;LONG RAW&#8221; :<br />
      $res["php_type"]=&#8221;string&#8221;;<br />
      $res["php_subtype"]=&#8221;blob&#8221;;<br />
      break;<br />
     case &#8220;NUMBER&#8221; :<br />
      if ($res[$i]["format"]) {<br />
       $res["php_type"]=&#8221;double&#8221;;<br />
       $res["php_subtype"]=&#8221;";<br />
      } else {<br />
       $res["php_type"]=&#8221;int&#8221;;<br />
       $res["php_subtype"]=&#8221;";<br />
      }<br />
      break;<br />
     default :<br />
      $this-&gt;halt(&#8221;metadata(): Type is not a valid value: &#8216;$res[$i][type]&#8216;&#8221;);<br />
      break;<br />
    }<br />
   }<br />
   if ($full) $res["meta"][$res[$i]["name"]] = $i;<br />
   $i++;<br />
  }<br />
  if ($full) $res["num_fields"]=$i;<br />
  # $this-&gt;disconnect();<br />
  return $res;<br />
 }</p>
<p> ## THIS FUNCTION IS UNSTESTED!<br />
 function affected_rows() {<br />
  if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: affected_rows=&#8221;. ora_numrows($this-&gt;Query_ID).&#8221;&lt;BR&gt;&#8221;;<br />
  return ora_numrows($this-&gt;Query_ID);<br />
 }</p>
<p> ## Known bugs: It will not work for SELECT DISTINCT and any<br />
 ## other constructs which are depending on the resulting rows.<br />
 ## So you *really need* to check every query you make, if it<br />
 ## will work with it!<br />
 ##<br />
 ## Also, for a qualified replacement you need to parse the<br />
 ## selection, cause this will fail: &#8220;SELECT id, from FROM &#8230;&#8221;).<br />
 ## &#8220;from&#8221; is &#8211; as far as I know a keyword in Oracle, so it can<br />
 ## only be used in this way. But you have been warned.<br />
 function num_rows() {<br />
  $curs=ora_open($this-&gt;Link_ID);</p>
<p>  ## this is the important part and it is also the HACK!<br />
  if (eregi(&#8221;^[[:space:]]*SELECT[[:space:]]&#8221;,$this-&gt;lastQuery) )<br />
  {</p>
<p>   # This works for all?? cases, including SELECT DISTINCT case.<br />
   # We just make select count(*) from original sql expression<br />
   # and remove ORDER BY (if any) for speed<br />
   # I like regular expressions too ;-)))<br />
   $q = sprintf(&#8221;SELECT COUNT(*) FROM (%s)&#8221;,<br />
   @eregi_Replace(&#8221;ORDER[[:space:]]+BY[^)]*()*)&#8221;, &#8220;\1&#8243;,<br />
   $this-&gt;lastQuery)<br />
   );</p>
<p>   # works also for subselects:<br />
   # if (eregi(&#8221;[[:space:]]+FROM([[:space:]]+.*[[:space:]]+FROM)&#8221;,$this-&gt;lastQuery,$r))<br />
   # $areplace=$r[1];<br />
   # $q=eregi_Replace(&#8221;^[[:space:]]*SELECT[[:space:]]+&#8221;.<br />
   # &#8220;.*[[:space:]]+FROM&#8221;,<br />
   # &#8220;SELECT COUNT(*) FROM$areplace&#8221;,<br />
   # $this-&gt;lastQuery);</p>
<p>   if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: num_rows: $q&lt;BR&gt;&#8221;;</p>
<p>   ORA_parse($curs,$q);<br />
   ORA_exec($curs);<br />
   ORA_fetch($curs);<br />
   $result = ORA_getcolumn($curs,0);<br />
   ORA_close($curs);<br />
   if ($this-&gt;Debug)<br />
   {<br />
    echo &#8220;&lt;BR&gt;Debug: ID &#8220;.$this-&gt;QueryID.<br />
    &#8221; num_rows=&#8221;. $result .&#8221;&lt;BR&gt;&#8221;;<br />
   }<br />
   return $result;<br />
  }<br />
  else<br />
  {<br />
   $this-&gt;halt(&#8221;Last Query was not a SELECT: $this-&gt;lastQuery&#8221;);<br />
  }<br />
 }</p>
<p> function num_fields() {<br />
  if ($this-&gt;Debug) echo &#8220;&lt;BR&gt;Debug: num_fields=&#8221;. ora_numcols($this-&gt;Query_ID) . &#8220;&lt;BR&gt;&#8221;;<br />
  return ora_numcols($this-&gt;Query_ID);<br />
 }</p>
<p> function nf() {<br />
  return $this-&gt;num_rows();<br />
 }</p>
<p> function np() {<br />
  print $this-&gt;num_rows();<br />
 }</p>
<p> function f($Name) {<br />
  return $this-&gt;Record[$Name];<br />
 }</p>
<p> function p($Name) {<br />
  print $this-&gt;Record[$Name];<br />
 }</p>
<p> /* public: sequence number */<br />
 function nextid($seq_name)<br />
 {<br />
  $this-&gt;connect();</p>
<p>  /* Independent Query_ID */<br />
  $Query_ID = ora_open($this-&gt;Link_ID);</p>
<p>  if(!@ora_parse($Query_ID,&#8221;SELECT $seq_name.NEXTVAL FROM DUAL&#8221;))<br />
  {<br />
   // There is no such sequence yet, then create it<br />
   if(!@ora_parse($Query_ID,&#8221;CREATE SEQUENCE $seq_name&#8221;)<br />
   ||<br />
   !@ora_exec($Query_ID)<br />
   )<br />
   {<br />
    $this-&gt;halt(&#8221;&lt;BR&gt; nextid() function &#8211; unable to create sequence&#8221;);<br />
    return 0;<br />
   }<br />
   @ora_parse($Query_ID,&#8221;SELECT $seq_name.NEXTVAL FROM DUAL&#8221;);<br />
  }<br />
  if (!@ora_exec($Query_ID)) {<br />
   $this-&gt;halt(&#8221;&lt;BR&gt;ora_exec() failed:&lt;BR&gt;nextID function&#8221;);<br />
  }<br />
  if (@ora_fetch($Query_ID) ) {<br />
   $next_id = ora_getcolumn($Query_ID, 0);<br />
  }<br />
  else {<br />
   $next_id = 0;<br />
  }<br />
  if ( $Query_ID &gt; 0 ) {<br />
   ora_close($Query_ID);<br />
  }</p>
<p>  return $next_id;<br />
 }</p>
<p> function disconnect() {<br />
  if($this-&gt;Debug) {<br />
   echo &#8220;Debug: Disconnecting $this-&gt;Query_ID&#8230;&lt;br&gt;n&#8221;;<br />
  }<br />
  if ( $this-&gt;Query_ID &lt; 1 ) {<br />
   echo &#8220;&lt;B&gt;Warning&lt;/B&gt;: disconnect(): Cannot free ID $this-&gt;Query_IDn&#8221;;<br />
   # return();<br />
  }<br />
  ora_close($this-&gt;Query_ID);<br />
  $this-&gt;Query_ID=0;<br />
 }</p>
<p> /* private: error handling */<br />
 function halt($msg) {<br />
  if ($this-&gt;Halt_On_Error == &#8220;no&#8221;)<br />
  return;</p>
<p>  $this-&gt;haltmsg($msg);</p>
<p>  if ($this-&gt;Halt_On_Error != &#8220;report&#8221;)<br />
  die(&#8221;Session halted.&#8221;);<br />
 }</p>
<p> function haltmsg($msg) {<br />
  printf(&#8221;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;&lt;b&gt;Database error:&lt;/b&gt; %s&lt;br&gt;n&#8221;, $msg);<br />
  printf(&#8221;&lt;b&gt;Oracle Error&lt;/b&gt;: %s (%s)&lt;br&gt;n&#8221;,<br />
  $this-&gt;Errno,<br />
  $this-&gt;Error);<br />
 }</p>
<p> function table_names() {<br />
  $this-&gt;connect();<br />
  $this-&gt;query(&#8221;<br />
SELECT table_name,tablespace_name<br />
FROM user_tables&#8221;);<br />
  $i=0;<br />
  while ($this-&gt;next_record())<br />
  {<br />
   $info[$i]["table_name"] =$this-&gt;Record["table_name"];<br />
   $info[$i]["tablespace_name"]=$this-&gt;Record["tablespace_name"];<br />
   $i++;<br />
  }<br />
  return $info;<br />
 }<br />
 // Some transaction support<br />
 // Methods are used in ct_oracle.inc<br />
 function begin_transaction()<br />
 {<br />
  $this-&gt;connect();<br />
  // Now, disable autocommit<br />
  Ora_CommitOff($this-&gt;Link_ID);<br />
  if ($this-&gt;Debug)<br />
  {<br />
   print &#8220;BEGIN TRANSACTION&lt;BR&gt;&#8221;;<br />
  }<br />
 }<br />
 function end_transaction()<br />
 {<br />
  if ($this-&gt;Debug)<br />
  {<br />
   print &#8220;BEGIN TRANSACTION&lt;BR&gt;&#8221;;<br />
  }</p>
<p>  $res = 1;<br />
  if(!@Ora_Commit($this-&gt;Link_ID))<br />
  {<br />
   Ora_CommitOn($this-&gt;Link_ID);<br />
   $this-&gt;halt(&#8221;Unable to finish transaction&#8221;);<br />
   $res = 0;<br />
  }<br />
  // Enable autocommit again<br />
  Ora_CommitOn($this-&gt;Link_ID);</p>
<p>  if ($this-&gt;Debug)<br />
  {<br />
   print &#8220;END TRANSACTION : $res&lt;BR&gt;&#8221;;<br />
  }<br />
  return $res;<br />
 }<br />
}<br />
?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/oracle-class-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

