简体   繁体   中英

UNION SELECT mysql php pdo no value return

SELECT t1.case_num AS casenum, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
     NULL, NULL
FROM luponcase_tbl t1
WHERE t1.case_num = :id AND t1.status = :active
UNION
SELECT mhearing_number, mhearing_status, mhearing_number, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL
FROM luponcase_mediation_tbl t4
WHERE t4.case_num = :id AND t4.status = :active
UNION
SELECT mfileblob, mfile_type, mfilesize, mhearing_number, mnameoffile, NULL, NULL, NULL,
    NULL, NULL
FROM luponcase_mediation_reference_tbl t5
WHERE t5.case_num = :id AND t5.status = :active

This is my sql for union and i am not getting result so i tried to echo the result

while ($selected_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                        print_r($selected_row);
} 

to my surprise the result is

Array ( [casenum] => 14 [NULL] => ) 

I am assuming that the first value is ok then the NULL columns are not. How to make it in a way that i will get only the columns except the NULL ones.

连接到数据库时,可以设置一些属性来控制数据库查询返回Null和Empty字符串时PDO如何处理它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM