PHP and ORACLE multiple DB doesn`t work
Posted: Tue Jul 07, 2009 5:48 pm
Hi
I've been all day trying to find some clues on how to get data from two SSID on the same server (under Oracle 10g and PHP5 w/oci)
I'll explain:
The Oracle server has two schemas: datos and global.
datos: localhost:1521
SID: datos
global: localhost:1521
SID: global
in PHP this is the connection I'm trying now, after a whola day i tried to simplify to the fullest:
Line:-----
<?php
//STATEMENT 1
@ $link = oci_connect("user","password" ,"localhost"/"global");
echo "oci_fetch_array <br>";
$stmt = ociparse($link, "select rut from USUARIO");
ociexecute($stmt);
while ($r2 = oci_fetch_array($stmt, OCI_BOTH)) {
echo $r2;
}
OCIFreeStatement($stmt);
//STATEMENT 2
@ $conn1 = oci_new_connect("user", "password", "localhost"/"datos");
$SQL = "select id_usuario from USUARIO where id_empresa = '2'";
$stmt = ociparse($conn1,$SQL);
ociexecute($stmt);
while(OCIFetch($stmt)){
$valor = OCIResult($stmt,1);
}
echo $valor;
OCIFreeStatement($stmt);
?>
Both sentences are tested and working so there is no problem in the PHP code.
* I've noticed that no matter what type of code I try, it always seems to only access the datos schema and never even touches the global schema.
* The errors I get from this code:
Warning: ociparse() expects parameter 1 to be resource, boolean given in D:\www\index.php on line 12
Warning: ociexecute() expects parameter 1 to be resource, null given in D:\www\index.php on line 13
Warning: oci_fetch_array() expects parameter 1 to be resource, null given in D:\www\index.php on line 14
Warning: ocifreestatement() expects parameter 1 to be resource, null given in D:\www\index.php on line 18
after that, I succesfully get the result from the second statement ... so confusing
* In the begining I used the sabe user and password for both schemas, now I've changed them . In that time the error was related to tables that didn't exist so I got to the conclussion that PHP was only accesing the datos schema, as I menctioned before.
I don't know that else to do, and I'm thinking seriously on passing to another language.
I've made a Sw in Java that also access those two databases, it works perfectly, so I'm thinking that perhaps it's me who don't know how to write in PHP, or PHP's OCI that doesn't support this kind of acces to databases.
If somebody could show me some clues I'll be gratefull.
(I've also posted in oracle forums)
I've been all day trying to find some clues on how to get data from two SSID on the same server (under Oracle 10g and PHP5 w/oci)
I'll explain:
The Oracle server has two schemas: datos and global.
datos: localhost:1521
SID: datos
global: localhost:1521
SID: global
in PHP this is the connection I'm trying now, after a whola day i tried to simplify to the fullest:
Line:-----
<?php
//STATEMENT 1
@ $link = oci_connect("user","password" ,"localhost"/"global");
echo "oci_fetch_array <br>";
$stmt = ociparse($link, "select rut from USUARIO");
ociexecute($stmt);
while ($r2 = oci_fetch_array($stmt, OCI_BOTH)) {
echo $r2;
}
OCIFreeStatement($stmt);
//STATEMENT 2
@ $conn1 = oci_new_connect("user", "password", "localhost"/"datos");
$SQL = "select id_usuario from USUARIO where id_empresa = '2'";
$stmt = ociparse($conn1,$SQL);
ociexecute($stmt);
while(OCIFetch($stmt)){
$valor = OCIResult($stmt,1);
}
echo $valor;
OCIFreeStatement($stmt);
?>
Both sentences are tested and working so there is no problem in the PHP code.
* I've noticed that no matter what type of code I try, it always seems to only access the datos schema and never even touches the global schema.
* The errors I get from this code:
Warning: ociparse() expects parameter 1 to be resource, boolean given in D:\www\index.php on line 12
Warning: ociexecute() expects parameter 1 to be resource, null given in D:\www\index.php on line 13
Warning: oci_fetch_array() expects parameter 1 to be resource, null given in D:\www\index.php on line 14
Warning: ocifreestatement() expects parameter 1 to be resource, null given in D:\www\index.php on line 18
after that, I succesfully get the result from the second statement ... so confusing
* In the begining I used the sabe user and password for both schemas, now I've changed them . In that time the error was related to tables that didn't exist so I got to the conclussion that PHP was only accesing the datos schema, as I menctioned before.
I don't know that else to do, and I'm thinking seriously on passing to another language.
I've made a Sw in Java that also access those two databases, it works perfectly, so I'm thinking that perhaps it's me who don't know how to write in PHP, or PHP's OCI that doesn't support this kind of acces to databases.
If somebody could show me some clues I'll be gratefull.
(I've also posted in oracle forums)