Problem returing Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
feralmo
Forum Newbie
Posts: 1
Joined: Tue May 30, 2006 8:00 am

Problem returing Array

Post 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]
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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; 
}
}
Post Reply