Avatar of tonelm54
tonelm54
 asked on

Return a record set with no rows

I use pdo to pull queries down from MySQL which has worked fine by using

$rs->fetchAll(PDO::FETCH_ASSOC);

Open in new window


The problem is when there is no rows to retrieve it returns an empty array (which I understand is right), however is there a way I can return the structure (the fields that would be returned) and if possible have the field values as null, so long as the fieldnames are available in the returned array


So, for example:-

SELECT * FROM `modules` WHERE `moduleID` =1;

Open in new window

Which returns 1 row:-

Which returns the array:-

Array
(
    [moduleID] => 1
    [title] => Employees and Contractors
    [permissionPath] => NULL
    [order] => 100
    [colorHex] => 436D5D
)

Open in new window


What I would like it is to use a query like:-

SELECT * FROM `modules` WHERE `moduleID` IS NULL

Open in new window

Which returns 0 rows:-

And Id like the returned array to be:-

Array
(
    [moduleID] => NULL
    [title] => NULL
    [permissionPath] => NULL
    [order] => NULL
    [colorHex] => NULL
)

Open in new window


Is this even possible

PHPSQL

Avatar of undefined
Last Comment
Chris Stanyon

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chris Stanyon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck