Jump to content
Fórum Script Brasil
  • 0

Funções Php Para Conectar No Oracle Ex: Ociparse


Guest Rubens Saad

Question

Guest Rubens Saad

Pessoal, é o seguinte fiz um aplicativo com oracle mas quando executa ocorre o seguinte erro:

Fatal error: Call to undefined function ocilogon() in C:\apachefriends\xampp\htdocs\index.php on line 5

Lembrando que retirei o comentario do extension=php_oracle.dll no PHP.ini

mas mesmo assim continua não funcionando.

Então executei em uma maquina que usava servidor de internet, e ela funcionava o ocilogon, mas quando coloquei a danada pra executar minha aplicação ocorre o seguinte:

Warning: ociparse(): supplied argument is not a valid OCI8-Statement resource

o mesmo com ociexecute():

ocifetch():

ocirollback():

preciso de ajuda, obrigado pessoal

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
Guest Rubens Saad

Cara a aplicação é grande e to rodando em windows e eu tenho as dlls na maquina:

pega ai:

<?php "db_oci8.inc"

function OracleErrorHandler ($errno, $errstr, $errfile, $errline) {

if ($errno != 2) {

echo "<b>ERROR</b> [$errno] $errstr<br>\n";

}

}

class DB_Sql {

var $Debug = 0;

var $sqoe = 1; // sqoe= show query on error

var $Persist = 0;

var $Database = "";

var $User = "";

var $Password = "";

var $Role = "";

var $RolePasswd = "";

var $Link_ID = 0;

var $Record = array();

var $Row;

var $Parse;

var $Error = "";

# Acrescentado em razao da execucao de procedures

var $ret;

var $nlinhas = 0;

# $teste

var $teste;

var $teste2;

function connect() {

if ( 0 == $this->Link_ID ) {

## Atribui as variaveis de ambiente

if($this->Debug) {

printf("<br>Connecting to $this->Database...<br>\n");

}

# Verifica se a conexão é persistente

set_error_handler("OracleErrorHandler");

if($this->Persist != 0) {

$this->Link_ID=OCIpLogon("usuario","senha","banco");

}

else{

$this->Link_ID=OCILogon("usuario","senha","banco");

}

restore_error_handler();

if (!$this->Link_ID) {

$this->Error=OCIError();

}

if (!$this->Link_ID && $this->Debug) {

$this->halt("Link-ID == false "."($this->Link_ID), OCILogon failed");

}

if ($this->Role != "")

$this->query(sprintf("SET ROLE %s IDENTIFIED BY %s",

$this->Role, $this->RolePasswd));

if($this->Debug) {

printf("<br>Obtained the Link_ID: $this->Link_ID<br>\n");

}

if (!$this->Link_ID) return false;

else return true;

}

return true;

}

function query($Query_String) {

$this->connect();

$this->Parse=OCIParse($this->Link_ID,$Query_String);

if(!$this->Parse) {

$this->Error=OCIError($this->Parse);

} else {

@ OCIExecute($this->Parse);

$this->Error=OCIError($this->Parse);

}

$this->Row=0;

if($this->Debug) {

printf("Debug: query = %s<br>\n", $Query_String);

}

if ($this->Error["code"]!=1403 && $this->Error["code"]!=0 && $this->sqoe)

echo "<BR><FONT color=red><B>".$this->Error["message"]."<BR>Query :\"$Query_String\"</B></FONT>";

return $this->Parse;

}

function prepare($Query_String) {

$this->connect();

$this->Parse=OCIParse($this->Link_ID,$Query_String);

if(!$this->Parse) {

$this->Error=OCIError($this->Parse);

}

if($this->Debug) {

printf("Debug: query = %s<br>\n", $Query_String);

}

if ($this->Error["code"]!=1403 && $this->Error["code"]!=0 && $this->sqoe)

echo "<BR><FONT color=red><B>".$this->Error["message"]."<BR>Query :\"$Query_String\"</B></FONT>";

return $this->Parse;

}

function execute() {

if($this->Parse) {

$lsRetorno = OCIExecute($this->Parse);

$this->Error=OCIError($this->Parse);

}

$this->Row=0;

if ($this->Error["code"]!=1403 && $this->Error["code"]!=0 && $this->sqoe)

echo "<BR><FONT color=red><B>".$this->Error["message"]."</B></FONT>";

return $lsRetorno;

}

function param($psParametro, $psLength) {

return OCIBindByName($this->Parse, ":" . $psParametro, $this->Record[ "$psParametro" ], $psLength);

}

function dec($valor) {

$valor = stripslashes($valor);

$valor = str_replace("('","(<aspas/>",$valor);

$valor = str_replace("')","<aspas/>)",$valor);

$valor = str_replace("','","<aspas/>,<aspas/>",$valor);

$valor = str_replace("', '","<aspas/>,<aspas/>",$valor);

$valor = str_replace("' ,'","<aspas/>,<aspas/>",$valor);

$valor = str_replace("' , '","<aspas/>,<aspas/>",$valor);

$valor = str_replace("' ,","<aspas/>,",$valor);

$valor = str_replace("',","<aspas/>,",$valor);

$valor = str_replace(", '",",<aspas/>",$valor);

$valor = str_replace(",'",",<aspas/>",$valor);

$valor = str_replace("'","\"",$valor);

return str_replace("<aspas/>","'",$valor);

}

function enc($valor) {

if ( gettype($valor) == "object" ) $valor = $valor->load();

$valor = htmlentities($valor);

$valor = str_replace("&amp;nbsp;","&nbsp;",$valor);

$valor = str_replace("&lt;i&gt;","<i>",$valor);

$valor = str_replace("&lt;/i&gt;","</i>",$valor);

## " -->&quot;

return $valor;

}

function executeRefCursor($sql) {

$this->ret = null;

$this->ret2 = null;

# $sqlexec = "BEGIN :refcur := " . $sql . " ; END;";

$sqlexec = "BEGIN :refcur := " . $this->dec($sql) . " ; END;";

# echo "<br>exec-> " . $sqlexec;

$stm = OCIParse($this->Link_ID,$sqlexec);

$refcur = OCINewCursor($this->Link_ID);

OCIBindByName($stm, ":refcur", $refcur, -1 , OCI_B_CURSOR);

OCIExecute ($stm);

OCIExecute ($refcur);

$results = null;

$nrows = OCIFetchStatement($refcur,$results1);

$nx = 0;

$ny = 0;

$this->nlinhas = $nrows;

# Retorno

$this->teste = $nrows;

if ($nrows > 0 ) {

# A primeira linha fica com os campos

while ( list($key, $val ) = each( $results1 ) ) {

#$this->ret[$ny][$nx] = $key;

$nx++;

}

# A partir da segunda linha ficam os resultados

$ny++;

for ( $i = 0; $i < $nrows; $i++ ) {

reset($results1);

$nx = 0;

while ( $column = each($results1) ) {

$data = $column['value'];

#if ($data[$i] != "20000 - ORA-00936: expressão ausente")

$this->ret2[$ny][$nx] = $data[$i];

$nx++;

}

$ny++;

}

}

else {

$this->ret2 = "";

}

#Eliminando duplicados

$retold = "-limpo-";

$num = 0;

for ($ny=0; $ny<= sizeof($this->ret2); $ny++) {

if ($retold != $this->ret2[$ny][2]) {

$this->ret[$num][0] = $this->ret2[$ny][0];

$this->ret[$num][1] = $this->ret2[$ny][1];

$this->ret[$num][2] = $this->ret2[$ny][2];

$retold = $this->ret2[$ny][2];

$num++;

}

}

OCIFreeStatement ($stm);

OCIFreeCursor ($refcur);

$stm = null;

$refcur = null;

$results1 = null;

$this->disconnect();

$this->connect();

}

function next_record() {

if(0 == @ OCIFetchInto($this->Parse,$result,OCI_ASSOC+OCI_RETURN_NULLS)) {

if ($this->Debug) {

printf("<br>ID: %d,Rows: %d<br>\n",

$this->Link_ID,$this->num_rows());

}

$this->Row +=1;

$errno=OCIError($this->Parse);

if(1403 == $errno) { # 1043 means no more records found

$this->Error=";

$this->disconnect();

$stat=0;

} else {

$this->Error=OCIError($this->Parse);

if($this->Debug) {

printf("<br>Error: %s",

$this->Error["message]);

}

$stat=0;

}

} else {

for($ix=1;$ix<=OCINumcols($this->Parse);$ix++) {

$col=strtoupper(OCIColumnname($this->Parse,$ix));

$colreturn=strtolower($col);

$this->Record[ "$colreturn" ] = $result["$col"];

if($this->Debug) echo"<b>[$col]</b>:".$result["$col"]."<br>\n";

}

$stat=1;

}

return $stat;

}

function seek($pos) {

$this->Row=$pos;

}

function metadata($table,$full=false) {

$count = 0;

$id = 0;

$res = array();

/*

* Due to compatibility problems with Table we changed the behavior

* of metadata();

* depending on $full, metadata returns the following values:

*

* - full is false (default):

* $result[]:

* [0]["table"] table name

* [0]["name"] field name

* [0]["type"] field type

* [0]["len"] field length

* [0]["flags"] field flags ("NOT NULL", "INDEX")

* [0]["format"] precision and scale of number (eg. "10,2") or empty

* [0]["index"] name of index (if has one)

* [0]["chars"] number of chars (if any char-type)

*

* - full is true

* $result[]:

* ["num_fields"] number of metadata records

* [0]["table"] table name

* [0]["name"] field name

* [0]["type"] field type

* [0]["len"] field length

* [0]["flags"] field flags ("NOT NULL", "INDEX")

* [0]["format"] precision and scale of number (eg. "10,2") or empty

* [0]["index"] name of index (if has one)

* [0]["chars"] number of chars (if any char-type)

* ["meta"][field name] index of field named "field name"

* The last one is used, if you have a field name, but no index.

* Test: if (isset($result['meta']['myfield'])) {} ...

*/

$this->connect();

## This is a RIGHT OUTER JOIN: "(+)", if you want to see, what

## this query results try the following:

## $table = new Table; $db = new my_DB_Sql; # you have to make

## # your own class

## $table->show_results($db->query(see query vvvvvv))

##

$this->query("SELECT T.table_name,T.column_name,T.data_type,".

"T.data_length,T.data_precision,T.data_scale,T.nullable,".

"T.char_col_decl_length,I.index_name".

" FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I".

" WHERE T.column_name=I.column_name (+)".

" AND T.table_name=I.table_name (+)".

" AND T.table_name=UPPER('$table') ORDER BY T.column_id");

$i=0;

while ($this->next_record()) {

$res[$i]["table"] = $this->Record[table_name];

$res[$i]["name"] = strtolower($this->Record[column_name]);

$res[$i]["type"] = $this->Record[data_type];

$res[$i]["len"] = $this->Record[data_length];

if ($this->Record[index_name]) $res[$i]["flags"] = "INDEX ";

$res[$i]["flags"] .= ( $this->Record[nullable] == 'N') ? '' : 'NOT NULL';

$res[$i]["format"]= (int)$this->Record[data_precision].",".

(int)$this->Record[data_scale];

if ("0,0"==$res[$i]["format"]) $res[$i]["format"]=';

$res[$i]["index] = $this->Record[index_name];

$res[$i]["chars"] = $this->Record[char_col_decl_length];

if ($full) {

$j=$res[$i]["name"];

$res["meta"][$j] = $i;

$res["meta"][strtoupper($j)] = $i;

}

if ($full) $res["meta"][$res[$i]["name"]] = $i;

$i++;

}

if ($full) $res["num_fields"]=$i;

# $this->disconnect();

return $res;

}

function affected_rows() {

return $this->num_rows();

}

function num_rows() {

return OCIrowcount($this->Parse);

}

function num_fields() {

return OCINumcols($this->Parse);

}

function nf() {

return $this->num_rows();

}

function np() {

print $this->num_rows();

}

function f($Name) {

return $this->enc($this->Record[$Name]);

}

function fd($Name) {

return $this->Record[$Name];

}

function flob($Name) {

return $this->Record[$Name]->load();

}

function p($Name) {

print $this->Record[$Name];

}

function disconnect() {

#if($this->Debug) {

# printf("Disconnecting...<br>\n");

#}

OCILogoff($this->Link_ID);

}

function halt($msg) {

printf("<b>Database error:</b> %s<br>\n", $msg);

printf("<b>ORACLE Error</b>: %s<br>\n",

$this->Error["message"]);

die("Session halted.");

}

function lock($table, $mode = "write") {

$this->connect();

if ($mode == "write") {

$Parse=OCIParse($this->Link_ID,"lock table $table in row exclusive mode");

OCIExecute($Parse);

} else {

$result = 1;

}

return $result;

}

function unlock() {

return $this->query("commit");

}

function table_names() {

$this->connect();

$this->query("

SELECT table_name,tablespace_name

FROM user_tables");

$i=0;

while ($this->next_record())

{

$info[$i]["table_name"] =$this->Record["table_name"];

$info[$i]["tablespace_name"]=$this->Record["tablespace_name"];

$i++;

}

return $info;

}

function add_specialcharacters($query)

{

return str_replace("'","''",$query);

}

function split_specialcharacters($query)

{

return str_replace("''","'",$query);

}

function get_value_cursor(&$cursor) {

$temp="";

OCIFetchinto($cursor,$cols,OCI_ASSOC);

for ($i=0;$i<sizeof($cols);$i++) $temp .= $cols[$i]."<br>";

return $temp;

}

}

?>

valeu e desculpa qualuqer coisa ai.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      651.8k
×
×
  • Create New...