MSSQL use in PHP

61 views Asked by At

I am using the following PHP code to fetch data from my mssql table:

$query2 = "select kArtikel, cArtNr, fVKNetto, fUVP from tartikel";
$result = mssql_query($query2);
$a= array();
while ($row = mssql_fetch_assoc($result)) {
    $a['data'][] = $row;
}
echo json_encode($a);

Works perfectly fine as a first test. Now I modify the query to a more complex one:

$query2 = "
SELECT ABP.cArtNr AS 'Artikelnummer',
       MAX(SUBSTRING(ABP.cName,8,50)) AS 'Beschreibung',
       SUM(ABP.nQuantityPurchased) AS 'Anzahl',
       SUM(ABP.nQuantityPurchased) * MAX(AA.fPrice) AS 'Brutto-Umsatz'
FROM pf_amazon_bestellung
INNER JOIN pf_amazon_bestellungpos ABP ON pf_amazon_bestellung.kAmazonBestellung = ABP.kAmazonBestellung
INNER JOIN pf_amazon_angebot AA ON ABP.cArtNr = AA.cSellerSKU
WHERE dPurchaseDate >= DateAdd(DAY, DateDiff(DAY, 0, getDate()), 0)
  AND pf_amazon_bestellung.cOrderStatus <> 'Canceled'
GROUP BY ABP.cArtNr
";

Now with this query, I don't get any results. Just white page. First test of the small snipped "select kArtikel, cArtNr, fVKNetto, fUVP from tartikel" was perfectly fine, the longer query doesn't work.

I already deleted the aliases, put everything in one line... nothing helped.

Of course, the query is correct and when performing it in SSMS everything is working as it should.

What can I do to get this larger query working here in PHP?

Thank you for your help!

0

There are 0 answers