Skip to content
Advertisement

Can I fetch multiple different SQL statements in one times loop? in PHP

I have to query SQL-SERVER‘s Query and MYSQL‘s Query (That have the same result format but it’s difference database) , But I want to call them in one while loop in PHP, Can I do that?

Ex.

$mssql_query = mssql_query(..mssql..);
$mysql_query = mysql_query(..mysql..);
while( $mssql_rs = mssql_fetch_assoc($mssql_query)|| $mysql_sql = mysql_fetch_assoc($mysql_query) )
{               
    ..some action..
}

EDITED : I just have an solved answer. It’s work for me Idea from @Drew while(bContinue)

this my code

$mssql_query = mssql_query(..mssql..);
$mysql_query = mysql_query(..mysql..);
$continue = true;

while( $continue ){

    $ms_rs = mssql_fetch_assoc($mssql_query);
    $my_rs = mysql_fetch_assoc($mysql_query);

    if($ms_rs){ ..some action.. }
    if($my_rs ){ ..some action.. }

    $continue = $ms_rs|| $my_rs;

}

Thank you for all ideas.

Advertisement

Answer

I just had an answer. It’s working for me Idea from @Drew while($continue)

Here is my code

$mssql_query = mssql_query(..mssql..);
$mysql_query = mysql_query(..mysql..);
$continue = true;

while( $continue )

{               
    $ms_rs = mssql_fetch_assoc($mssql_query);
    $my_rs = mysql_fetch_assoc($mysql_query);
                
    if($ms_rs){ ..some action.. }
    if($my_rs ){ ..some action.. }

    $continue = $ms_rs|| $my_rs;

}

Thank you for all the ideas.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement