$stmt = $dbh->prepare( 'SELECT id, name FROM folders WHERE parent_folder_id = :id' ); $stmt->bindValue( ':id', $folder_id, PDO::PARAM_INT );
I have the code above. If the folder has parent_folder_id, then it is inside another folder. If this column is NULL, this means that this is the root folder.
From my understanding, if $ folder_id is NULL, then it will consider it equal to 0 (therefore, I do not get any results with the code, since this value in this column is NULL, not 0). If I change the third argument to PDO :: PARAM_NULL, I still do not get any results. I believe this is because it evaluates the query as "WHERE parent_folder_id = NULL", which does not match "WHERE parent_folder_id NULL".
Is there a way for PDO to relate to this correctly or do I need to create an SQL statement using inline if I change "=" to "is" and replace the third parameter of bindValue with the correct one?
Gazillion
source share