I’m using Msqli to make a multiquery, the query works exactly like i want within phpmyadmin.
it do not work with mysqli anymore. The query did not change between servers.
The query below Was working in a previous LAMP installation but not in the current.
$SQLquery ='set @type = \'\';
set @num = 1;
SELECT
RA.`DATE` as DATES,
RA.`ADDR` as ADDR,
RA.`QID` as QID,
RT.`TAGS` as TAG,
Q.`id` AS QUID,
Q.`ADDR` AS QADDR,
Q.`ORIGINALTEXT` AS QTEXTS,
Q.`DATE` AS QDATES,
cs.`id` AS CUID,
cs.`ADDR` AS CADDR,
cs.`ORIGINALTEXT` AS CTEXTS,
cs.`DATE` AS CDATES,
sol.`id` AS SUID,
sol.`ORIGINALTEXT` AS STEXTS,
sol.`ADDR` AS SADDR,
sol.`DATE` AS SDATES,
prj.`id` AS PUID,
prj.`ORIGINALTEXT` AS PTEXTS,
prj.`ADDR` AS PADDR,
prj.`DATE` AS PDATES,
Max(Q.`DATE` ) AS Q,
Max(cs.`DATE` ) AS C,
Max(sol.`DATE` ) AS S,
Max(prj.`DATE` ) AS P,
#@num as row_number
@num:= if(@type = RA.`ADDR`, 1+@num, 1) as v_number,
@type := RA.`ADDR` as dummy
FROM (SELECT `id`,`TAGS`, `QID` from `REL_TAG` ) AS RT
inner Join (SELECT `DATE`, `ADDR`, `QID` from `REL_ADDR` order by DATE) AS RA ON ( RT.`QID` = RA.`QID`)
Left outer Join (SELECT `id`,`DATE`, `ADDR`, `QID`, `ORIGINALTEXT` FROM `QUESTION`) AS Q ON ( RT.`QID` = Q.`QID`) and Q.`ADDR` = RA.`ADDR`
Left outer Join (SELECT `id`,`DATE`, `ADDR`, `QID`, `ORIGINALTEXT` FROM `CASES` order by `CASES`.`DATE`) AS cs ON ( RT.`QID` = cs.`QID`) and cs.`ADDR` = RA.`ADDR`
Left outer Join (SELECT `id`,`DATE`, `ADDR`, `QID`, `ORIGINALTEXT` FROM `SOLUTION` order by `SOLUTION`.`DATE`) AS sol ON ( RT.`QID` = sol.`QID`) and sol.`ADDR` = RA.`ADDR`
Left outer Join (SELECT `id`,`DATE`, `ADDR`, `QID`, `ORIGINALTEXT` FROM `PROJECT` order by `PROJECT`.`DATE`) AS prj ON ( RT.`QID` = prj.`QID`) and prj.`ADDR` = RA.`ADDR`
where RT.`QID` = \''.NbOnly($Fetchmodifier).'\' Group by `QID`, addr, v_number LIMIT '.$Anstart.' ,'.$Ansnb.';';
Update
The query does not return any error in the logs, it just return nothing (null).
Here is the PHP code to execute the MySQLi Multiquery
$mysqlin = new mysqli("localhost", "user", "pass", "db");
if (mysqli_error($mysqlin)) {
outputdataXML(sprintf("Connect Problem : %s\n", mysqli_error($mysqlin)));
exit();
}
if ($mysqlin->multi_query($SQLquery)) {
do {
if ($result = $mysqlin->store_result()) {
while ($row = $result->fetch_array(MYSQLI_BOTH)) {
if( $Foundrows = $row[0]){ //Maybe the problem is here ?
$Outputvalue[] = FormatFile($row);
}
}
$result->free();
}
if ($mysqlin->more_results()) {
}
} while ($mysqlin->more_results() && $mysqlin->next_result());
}
$mysqlin->close();
I have Found the problem, Some but not all of the tables Were EMPTY,
As in Without any records,
I added a dummy record To each tables, some tables had records but some were without,
and now even if the Query dont matchThe joins are Now still being Made properly.
I Hope this help lots of ppl.
When your using MySQL “Join”, you need 1 record in each and All of your joined tables, no matter if it will ever be used ex: 0, 00-00-0000, Null , 0, empty
Only then, all the joinning Tables included in the query will work.