query with temporary table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rosie
Forum Newbie
Posts: 2
Joined: Fri Oct 06, 2017 1:57 pm

query with temporary table

Post by rosie »

Hi,

I am new in php and I have a problem a push from your would be no refusal :p, my problem is when I execute the query in sql server its works normaly but when I execute its with php does not work empty result . thanks to helping me

here my code:

Code: Select all


$sql = "  

select t.Tan, SUM(s.TOP) as Top
into #TempEnj
from [Proses].[dbo].[CD_Dok] d
inner join [Proses].[dbo].[CD_Sar] s on(s.DOID = d.ID)
inner join [Proses].[dbo].[CT_Sa] t on (s.TANID= t.ID)

  where d.date ='2017-10-05'

   group by T.Tan

insert into #TempEnj values ('Enerji', (select sum(Enj) from [Proses].[dbo].[CD_Dok] where date ='2017-10-05'))
insert into #TempEnj values ('Sure', (select sum(Sure) from [Proses].[dbo].[CD_Dok] where date ='2017-10-05'))
select * from #TempEnj ";




$stmt5  sqlsrv_query( $conn, $sql );
if( $stmt == false ) {
    if( ($errors = sqlsrv_errors() ) != null) {
        foreach( $errors as $error ) {
            echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
            echo "code: ".$error[ 'code']."<br />";
            echo "message: ".$error[ 'message']."<br />";
        }
    }
}


$tab[]= array();
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
    $tab[] = $row;


}   
var_dump($tab);


User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: query with temporary table

Post by requinix »

If sqlsrv_query allows you to run multiple queries then they probably need to be delimited by semicolons, and you'd probably need to use sqlsrv_next_result() to go between the two/four resultsets.
rosie
Forum Newbie
Posts: 2
Joined: Fri Oct 06, 2017 1:57 pm

Re: query with temporary table

Post by rosie »

hi,

you are reight , sqlsrv_next_result() fixed my problem thank you :)
Post Reply