I try to run this query SQL
in PHP:
SELECT
M000.FULTACT000,
M000.NBCLI000,
M000.G300CTA,
(SELECT NCNL000 FROM BI_SRC.CNLF000 WHERE CUUID000 = M000.CUUID000),
(SELECT NALDF000 FROM BI_SRC.ALDF000 WHERE IDALDF000 = M000.IDALDF000),
(SELECT NBUSUF000 FROM BI_SRC.USEJE000 WHERE UIDEJE000 = M000.UIDEJE000)
FROM
BI_SRC.MRCJ000 M000
ORDER BY
M000.MRCJID000 DESC;
In Oracle database , everything is fine, but implementing it in PHP (the subqueries) gives me a couple of errors. Among them:
Undefined index: NCNL000 Undefined index: NALDF000 Undefined index: NBUSUF000
UPDATED CODE IN PHP
$stid = $conn->prepare("SELECT M000.FULTACT000, M000.NBCLI000, M000.G300CTA, (SELECT C000.NCNL000 FROM BI_SRC.CNLF000 C000 WHERE C000.CUUID000 = M000.CUUID000),(SELECT NALDF000 FROM BI_SRC.ALDF000 WHERE IDALDF000 = M000.IDALDF000),(SELECT NBUSUF000 FROM BI_SRC.USEJE000 WHERE UIDEJE000 = M000.UIDEJE000)
FROM BI_SRC.MRCJ000 M000
ORDER BY M000.MRCJID000 DESC");
$stid->execute();
while ($row = $stid->fetch(PDO::FETCH_ASSOC)) {// obtener resultados está línea hace falta
$fecha[] = $row['FULTACT000'];
$cliente[] = $row['NBCLI000'];
$cuenta[] = $row['G300CTA'];
$canal[] = $row['NCNL000'];
$aliado[] = $row['NALDF000'];
$gerente[] = $row['NBUSUF000'];
}
PHP is right, there is no such index in the results, the index is called
So, I know. If you paste that query into your DB you will see that the headers it returns are not called NCNL000 but the whole query. You solve that by putting the alias you need
I add , why are you doing subqueries instead of JOINS? In large queries you will hit the performance of the DB, it is better to normalize from now on and save yourself the trouble.
Let it serve you