Ver Mensaje Individual
  #11 (permalink)  
Antiguo 07/12/2007, 09:53
leo_25
 
Fecha de Ingreso: agosto-2004
Ubicación: Lima
Mensajes: 109
Antigüedad: 19 años, 8 meses
Puntos: 1
Re: ejecutar store procedure en mysql desde php

la verdad es que para ejecutar un store procedure en mi caso usando ADODB solo es posible con php5.. y mysql 5.. aqui dejo script espero les sea util
FetchUtil.php
Código PHP:
<?php
class FetchUtil {
     
    var 
$row;
    var 
$DB_type;
    var 
$DB
    function 
FetchUtil($dsn){
        
$this->DB NewADOConnection($dsn);
        if ( !
$this->DB ) die("Conexion fallida - $dsn");
        
$this->DB->SetFetchMode(ADODB_FETCH_ASSOC);
    }
    function 
Execute($query='select now()'){
        
$this->row  $this->DB->Execute($query) or die ($this->DB->ErrorMsg());
    }
    function 
FetchAll($query){
        
        
$this->Execute($query);
        while(!
$this->row->EOF){
            
$temp[] = $this->row->fields;
            
$this->row->MoveNext();
        } 
        return 
$temp
    }

    function 
FetchAllArray($query,$key,$value) {
        
$this->Execute($query);
        while(!
$this->row->EOF){
            
$temp[$this->row->fields[$key]] = $this->row->fields[$value];
            
$this->row->MoveNext();
        } 
        return 
$temp
    }
    function 
qstr($string) {
        return 
$this->DB->qstr($string,get_magic_quotes_gpc());
    }
}
?>

y el test es:
index_2.php

Código PHP:
<?php
require_once('adodb/adodb.inc.php'); 
require_once(
'FetchUtil.php');
$data_base 'mysql';
$user 'root';
$passwd '';
$host 'localhost';
$db_name 'ejemplo';
$dsn "$data_base://$user:$passwd@$host/$db_name?clientflags=65536";
$db = new FetchUtil($dsn);

$row $db->fetchAll("CALL select_emps()");/*llamada al store procedure*/
echo "<pre>";
print_r($row);
echo 
"</pre>";
?>