Page 1 of 1

Calling ORACLE procedure from PHP big problem!!!

Posted: Tue Jan 10, 2012 1:38 pm
by denonth
Hi guys it's my first post here so please help if you know how to handle this problem.

I am developing php scripts that I will call with certain methods from another programming language but this is not important right now... Because I am trying to make my code work from php page first.
So I am using php to connect to Oracle database, I have few scripts, I will put the code in but not all of it so if you need more details please ask.
First I have this class, for communicating with Oracle database ( this is whole file ):

Code: Select all

<?PHP
class oracle_baza {
	static function Exec($query) {
		//otvaranje konekcije s bazom
		$conn = oci_connect(
			$GLOBALS['cfg_db_User'],
			$GLOBALS['cfg_db_Pass']
			);
		if($conn === false) {
			throw new Exception(oci_connect_error());
		}
	
		//izvedemo query
		$s = oci_parse($conn, $query);
		$rez = oci_execute($s);
		
		if(is_bool($rez) && !$rez) {
			//greska
			$napaka = oci_error($conn);
			oci_close($conn);
			throw new Exception($napaka);
		}

		//zatvorimo konekciju
		oci_close($conn);
		
		return $rez;
	}
?>
Then I have this class that is making me phonebook class ( sorry if it's not in english) but I think you'll be able to see what is what inside ( i will just post few functions )....

Code: Select all

//funckija za pohranjivanje podataka
	function Dodaj_korisnika(){
		$query="CALL Dodaj_korisnika('$this->ime_korisnika','$this->prezime_korisnika','$this->broj_telefona','$this->adresa')";
		$result=$this->connector->Exec($query);
	}
	//funkcija za brisanje
	function Brisanje_korisnika(){
		$query='BEGIN Brisanje_korisnika(:id_korisnika);END;';
		oci_bind_by_name($query,':id_korisnika',$this->id_korisnika,32);
		$result=$this->connector->Exec($query);
	}
	//funckija za update podataka
	function Update_korisnika(){
		$query="CALL Update_korisnika('$this->id_korisnika',$this->ime_korisnika','$this->prezime_korisnika','$this->broj_telefona','$this->adresa')";
		$result=$this->connector->Exec($query);
	}
As you can see I have tried several ways of executing this code but it doesn't work.
These variable I get from another class and I have constructor like this:

Code: Select all

public function __construct($id_korisnika,$ime_korisnika, $prezime_korisnika, $broj_telefona,$adresa) {
		$this->id_korisnika = $id_korisnika;
		$this->ime_korisnika =$ime_korisnika;
		$this->prezime_korisnika = $prezime_korisnika;
		$this->broj_telefona = $broj_telefona;
		$this->adresa = $adresa;
		$this->connector = new oracle_baza();
	}
So basically I am getting all kind of error's. So If anyone can give me some info about what is incorrect and what to do. So I want call certain stored procedures in oracle database from php code.

Thank you in advance,
Denonth

Re: Calling ORACLE procedure from PHP big problem!!!

Posted: Tue Jan 10, 2012 3:23 pm
by mikosiko
So basically I am getting all kind of error's
without seeing the errors or the SP code (to validate if it has IN/OUT parameter and lengths) or if it return a single or multi-result is hard to tell you what could be possible wrong

Re: Calling ORACLE procedure from PHP big problem!!!

Posted: Tue Jan 10, 2012 3:29 pm
by denonth
I am sorry I forgot to put error I get:

[text]Warning: oci_bind_by_name() expects parameter 1 to be resource, string given in C:\Program Files\EasyPHP-5.4.0beta1\www\imenik.php on line 39

Warning: oci_execute(): ORA-01008: not all variables bound in C:\Program Files\EasyPHP-5.4.0beta1\www\oracle_baza.php on line 22
[/text]

This is for example when I am calling this procedure:

Code: Select all

function Brisanje_korisnika(){
		$query='BEGIN Brisanje_korisnika(:id_korisnika);END;';
		oci_bind_by_name($query,":id_korisnika",$this->id_korisnika);
		$result=$this->connector->Exec($query);
	}
Which is procedure for deleting one entry from database that depends on sended id.

Here is how the procedure is made in Oracle:

CREATE OR REPLACE PROCEDURE Brisanje_korisnika(
id_korisnika IN number)

AS
BEGIN
DELETE FROM Korisnici WHERE Korisnici.id_korisnika = id_korisnika;
END;
/

I apologize one more time...I just forgot to put this stuff.

Thank you,
Denonth

Re: Calling ORACLE procedure from PHP big problem!!!

Posted: Tue Jan 10, 2012 4:35 pm
by denonth
Anyone please? This is so important for me...I am reading all forums all night but I have done everything similar to others. And it's not working.

Re: Calling ORACLE procedure from PHP big problem!!!

Posted: Tue Jan 10, 2012 6:07 pm
by mikosiko
I don't see that you are using oci_parse() before you call to oci_bind_by_name... you are just passing a string instead of a a resource... here you can find examples
http://php.net/manual/en/function.oci-bind-by-name.php

Re: Calling ORACLE procedure from PHP big problem!!!

Posted: Wed Jan 11, 2012 3:47 am
by denonth
I have oci_parse() in class that is working with my connection.
How would I change that so I can just execute query in that class, and bind with parse in another class..
If you can see in above code.

Re: Calling ORACLE procedure from PHP big problem!!!

Posted: Wed Jan 11, 2012 8:31 am
by mikosiko
in the link provided the 4th user's contributed example show you a way to implement it.

Re: Calling ORACLE procedure from PHP big problem!!!

Posted: Wed Jan 11, 2012 8:52 am
by denonth
Thank you.