Note Submitter: sandinosaso at gmail dot com
----
A nice and simple function to call a stored procedure in an Oracle DataBase...it works great for me !!!
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ñ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;";
$id_sentencia = ociparse($conexion, $procedure);
if (!$id_sentencia) {
$error = oci_error($conexion);
$msg_error = 'Error al procesar la modificació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;
}
}
if (!$any_error){
$resultado = ociexecute($id_sentencia);
if (!$resultado) {
$error = oci_error($id_sentencia);
$msg_error = 'Error al realizar la modificació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;";
$id_sentencia = ociparse($conexion, $procedure);
if (!$id_sentencia) {
$error = oci_error($conexion);
$msg_error = 'Error al procesar la modificació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;
}
}
if (!$any_error){
$resultado = ociexecute($id_sentencia);
if (!$resultado) {
$error = oci_error($id_sentencia);
$msg_error = 'Error al realizar la modificació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.