note 98017 deleted from function.oci-parse by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: sandinosaso at gmail dot com 

----

A nice function to call an oracle procedure in an Oracle Database.
$usuario: database user
$password: database user password
$nombre_procedure: the procedure name
$parametros: a simple array containing the procedure's parameters
$conexion: a link connection (optional)

function ejecutarProcedure ($usuario, $password, $nombre_procedure, $parametros, $conexion = FALSE)
{
$any_error = FALSE;
$msg_error = '';
$error = '';
	

	if (!$conexion){
		$conexion = ocilogon($usuario, generarPass($usuario, $password), BD);
    
		if (!$conexion) {
		 	$msg_error = 'El usuario o la contrase&ntilde;a es incorrecto.';
	 		$any_error = TRUE;

		} else {
			
			$procedure= "BEGIN " . $nombre_procedure . "("; 
			for($i=1; $i <= count($parametros); $i++){
				$procedure .= ":param" . $i;
				if ($i < count($parametros))
					$procedure .= ", ";
			}	
			$procedure .= ");END;";	
			//echo "<br>PROCEDIMIENTO EJECUTADO: $procedure <br>";					
			$id_sentencia = ociparse($conexion, $procedure);
			
			if (!$id_sentencia) {
				$error = oci_error($conexion);
				$msg_error = 'Error al procesar la modificaci&oacute;n';
				$any_error = TRUE;
			}
			
			if (!$any_error){
				
				for($i=1; $i <= count($parametros); $i++){
					$valor = $parametros[$i];
					$nombre="var".$i;
					$$nombre=$valor;
					$param = ":param".$i;
					if (!ocibindbyname($id_sentencia, $param, $$nombre, 256)){
						$any_error = TRUE;
						$msg_erroy = 'Error al hacer bin';
						break;
					}
					//echo "<br>PARAMETRO: $param --- VALOR: $valor<br>";
				}
					if (!$any_error){	
						$resultado = ociexecute($id_sentencia);
			
						if (!$resultado) {
							$error = oci_error($id_sentencia);
							$msg_error = 'Error al realizar la modificaci&oacute;n';
							$any_error = TRUE;
						}
					}
			}
			ocilogoff($conexion);
		}
	} else {
		$procedure= "BEGIN " . $nombre_procedure . "("; 
			for($i=1; $i <= count($parametros); $i++){
				$procedure .= ":param" . $i;
				if ($i < count($parametros))
					$procedure .= ", ";
			}
	   	 $procedure .= ");END;";
		//echo "<br>PROCEDIMIENTO EJECUTADO: $procedure <br>";
		$id_sentencia = ociparse($conexion, $procedure);
		
		if (!$id_sentencia) {
			$error = oci_error($conexion);
			$msg_error = 'Error al procesar la modificaci&oacute;n';
			$any_error = TRUE;
		}
			
		if (!$any_error){
			for($i=1; $i <= count($parametros); $i++){
					$valor = $parametros[$i];
					$nombre="var".$i;
					$$nombre=$valor;
					$param = ":param".$i;
					if (!ocibindbyname($id_sentencia, $param, $$nombre, 256)){
						$any_error = TRUE;
						$msg_erroy = 'Error al hacer bin';
						break;
					}
					//echo "<br>PARAMETRO: $param --- VALOR: $valor<br>";
			}
				
			if (!$any_error){	
				$resultado = ociexecute($id_sentencia);
	
				if (!$resultado) {
					$error = oci_error($id_sentencia);
					$msg_error = 'Error al realizar la modificaci&oacute;n';
					$any_error = TRUE;
				}
			}
		}
		
	}
		
	return array ($any_error, $msg_error);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.