Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:21:30+00:00 2026-05-24T16:21:30+00:00

$stmt = $dbh->prepare( ‘SELECT id, name FROM folders WHERE parent_folder_id = :id’ ); $stmt->bindValue(

  • 0
$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 a folder has a parent_folder_id then it means it is inside another folder. If this column is NULL then it means that it is a root folder.

From my understanding if $folder_id is NULL then it will treat it as 0 (so I get no results with the code as it is because the value in that column is NULL and not 0). If I change the third argument to PDO::PARAM_NULL I still get no results. I believe this is because it evaluates the query as “WHERE parent_folder_id = NULL” which doesn’t equal the same as “WHERE parent_folder_id is NULL”.

Is there a way to have PDO treat this correctly or should I create my SQL statement with an inline if to change the “=” with “is” and swap the bindValue third parameter with the correct one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:21:31+00:00Added an answer on May 24, 2026 at 4:21 pm

    If you’re using MySQL, you can use the nonstandard NULL-safe equal operator <=>, which can compare either null or non-null values.

    $stmt = $dbh->prepare( 'SELECT id, name FROM folders WHERE parent_folder_id <=> :id' );
    $stmt->bindValue( ':id', $folder_id, PDO::PARAM_INT );
    

    This operator always returns true or false, not NULL, which is what you get if you try to compare anything to NULL with equals =.

    ANSI SQL defines a predicate IS [NOT] DISTINCT FROM which works similarly, but it’s not supported by all vendors (yet).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following prepared statement: $sql = PREPARE stmt_name FROM 'SELECT I.item_id, I.name
I have this query and I have an error: images = Image.find_by_sql('PREPARE stmt FROM
I am attempting to execute the following prepared statement: PREPARE stmt FROM 'SELECT *
Here's my code $stmt = $conn->mysqli->stmt_init(); $stmt = $conn->mysqli->prepare('SELECT Username, EmailVerified, Blocked FROM user
I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt
I'm writing this in JAVA : stmt.executeQuery(SELECT * FROM mytable INTO OUTFILE '/tmp/mytable.csv' FIELDS
The problem code: NSString *query = @SELECT Name FROM Category; sqlite3_stmt *statement; if (sqlite3_prepare_v2(database,
I have the following Java code: String query = Select 1 from myTable where
String query = select email from emp_select; Statement stmt; try { DB db=new DB();
PROCEDURE A( ... BEGIN stmt := 'select * from '||src; execute immediate stmt; dbms_output.put_line(??);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.