Page 1 of 1

Problem returing Array

Posted: Tue May 30, 2006 8:13 am
by feralmo
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I have developed a program that works with PHP 4 and when I tried to move it to a new site with PHP 5.0.5 is failing.

When calling to the function "ejecutarsql" the array is not returned, but the rows are detected.

Code: Select all

$query = "SELECT * FROM " . BD_TABLE . " $where ORDER BY Nombre $limit";

$rows = $bd -> ejecutarsql( $query );
if( $bd -> filas_resultantes( ) ) {
reset( $rows );
foreach ( $rows as $r ) {
}
Function code:

Code: Select all

function ejecutarsql( $instruccion, $num_rows = 0, $offset = 0 ) {
 $conn = $this -> db_conn;
 $resultado = false;
 for ( $i = 0; $i < NUM_REINTENTOS_EN_BLOQUEOS; $i++ ) {
  if ( $num_rows != 0 ) {
  $resultado = $conn -> SelectLimit( $instruccion, $num_rows, $offset );
  } else {
   $resultado = $conn -> Execute( $instruccion );
  }
  if ( $resultado != false ) {
   for ( $j = 0; $j < $resultado -> RecordCount(); $j++ ) {
    $aux[ $j ] = $resultado -> GetArray();
    $resultado -> NextRecordSet();
    $datos[ $j ] = $aux[ 0 ][ $j ];
  }
$this -> error = NO_ERROR;
$this -> resultado = $resultado;
echo "resultado".$datos;
return $datos;
} else {
continue;
}
}
$this -> error = ERR_BLOQUEO;
return false;
}
Doing a trace, the function is called and executed OK. When showing the "echo" before returning the Array I can see that the variable $datos has data.


Could anyone help?

Thanks.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 30, 2006 11:32 am
by tecktalkcm0391
I am a little confused please explain a little more.

Try this:

Code: Select all

function ejecutarsql( $instruccion, $num_rows = 0, $offset = 0 ) { 
 $conn = $this -> db_conn; 
 $resultado = false; 
 for ( $i = 0; $i < NUM_REINTENTOS_EN_BLOQUEOS; $i++ ) { 
  if ( $num_rows != 0 ) { 
  $resultado = $conn -> SelectLimit( $instruccion, $num_rows, $offset ); 
  } else { 
   $resultado = $conn -> Execute( $instruccion ); 
  } 
  if ( $resultado != false ) { 
   for ( $j = 0; $j < $resultado -> RecordCount(); $j++ ) { 
    $aux[ $j ] = $resultado -> GetArray(); 
    $resultado -> NextRecordSet(); 
    $datos[ $j ] = $aux[ 0 ][ $j ]; 
  } 
$this -> error = NO_ERROR; 
$this -> resultado = $resultado; 
echo "resultado".$datos; 
return $datos; 
} else { 

} 
$this -> error = ERR_BLOQUEO; 
return false; 
}
}