php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65421 'field=NULL' should be 'field IS NULL'
Submitted: 2013-08-08 13:26 UTC Modified: 2013-08-12 16:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: schwalenberg1013 at gmail dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.5.1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: schwalenberg1013 at gmail dot com
New email:
PHP Version: OS:

 

 [2013-08-08 13:26 UTC] schwalenberg1013 at gmail dot com
Description:
------------
When using PDO bindParam when it receives a NULL value the ultimate result that 
it sends to MySql is field=NULL instead of field IS NULL.

Test script:
---------------
                $editStmt = $db->prepare("UPDATE employee SET startDate=:startDate,department=:department,jobTitle=:jobTitle WHERE name=:emplName AND startDate=:oldStartDate AND department=:oldDepartment AND jobTitle=:oldJobTitle LIMIT 1");
                $editStmt->bindParam('startDate',$startDate);
                $editStmt->bindParam('department',$department);
                $editStmt->bindParam('jobTitle',$jobTitle);
                $editStmt->bindParam('emplName',$emplName);
                $editStmt->bindParam('oldStartDate',$oldStartDate);
                $editStmt->bindParam('oldDepartment',$oldDepartment);
                $editStmt->bindParam('oldJobTitle',$oldJobTitle);
// catchException($editStmt,$db);
                $editStmt->execute();
                $editResult = $editStmt->fetchAll(PDO::FETCH_ASSOC);

/* If any one of these variables happens to be NULL then the whole statement fails because it will output, for example, 'AND department=NULL' instead of 'AND department IS NULL' */

Expected result:
----------------
MySql will not except field=NULL properly it should be field IS NULL

Actual result:
--------------
I can do this in MySql however when using PDO I have to create an entirely 
different statement myself for the exceptions of NULL values which becomes very 
tedious a problem I never had using the depreciated mysql functions or when using 
mysqli.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-12 16:29 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2013-08-12 16:29 UTC] ab@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This won't work as you describe, a binding method will always affect only the 
defined container, so the question mark or :someval. Say if you have x=:y, 
bindParam will never touch the x= part. But what you can do is build the statement 
string dynamically and use the third bindParam argument on condition. Also you 
could try to explicitly cast string if that's ok with your database design.
 [2023-05-17 11:24 UTC] giw42161 at uooos dot com
(https://centurylawfirm.in/)gist.github.com


(https://www.centurylawfirm.in/blog/combating-mob-lynching-analysing-legal-frameworks-and-preventive-measures-for-a-safer-society/)gist.github.com
(https://www.centurylawfirm.in/blog/best-advocate-in-delhi-qualities-to-look-for-choosing-the-correct-one-for-you/)gist.github.com
(https://www.centurylawfirm.in/blog/understanding-the-process-of-making-a-police-complaint-in-india-a-guide-for-commoners/)gist.github.com
(https://www.centurylawfirm.in/blog/section-498a-of-the-indian-penal-code/)gist.github.com
(https://www.centurylawfirm.in/blog/when-do-you-need-to-hire-the-best-advocate-in-delhi/)gist.github.com

(https://www.centurylawfirm.in/blog/things-to-consider-before-choosing-a-criminal-lawyer-in-delhi/)gist.github.com
(https://www.centurylawfirm.in/blog/criminal-lawyer-in-delhi/)gist.github.com


(https://www.centurylawfirm.in/blog/lawyer-for-writ-petition/)gist.github.com
(https://www.centurylawfirm.in/blog/best-law-firm-in-delhi/)gist.github.com
(https://www.centurylawfirm.in/blog/best-law-firm-in-delhi/)gist.github.com
(https://www.centurylawfirm.in/blog/muslim-divorce-lawyer/)gist.github.com
(https://centurylawfirm.in/blog/how-to-take-mutual-divorce/)gist.github.com

(https://www.centurylawfirm.in/blog/things-to-consider-before-choosing-a-criminal-lawyer-in-delhi/)gist.github.com
(https://www.centurylawfirm.in/blog/criminal-lawyer-in-delhi/)gist.github.com


(https://centurylawfirm.in/blog/divorce-lawyer-in-delhi-2/)gist.github.com
(https://centurylawfirm.in/blog/debt-recovery-tribunal-drt/)gist.github.com
(https://centurylawfirm.in/blog/get-bail-in-india/)gist.github.com
(https://centurylawfirm.in/blog/best-lawyer-for-criminal-case/)gist.github.com
(https://centurylawfirm.in/blog/high-court-cases/)gist.github.com
(https://centurylawfirm.in/blog/cheque-bounce-case/)gist.github.com
(https://centurylawfirm.in/blog/how-to-take-mutual-divorce/)gist.github.com



(https://www.centurylawfirm.in/blog/payment-recovery-cases/)gist.github.com (https://www.centurylawfirm.in/blog/mutation/)gist.github.com (https://www.centurylawfirm.in/blog/loan-matters/)gist.github.com (https://www.centurylawfirm.in/blog/corporate-law/)gist.github.com (https://www.centurylawfirm.in/blog/law-firm/)gist.github.com (https://www.centurylawfirm.in/blog/divorce-lawyer-in-rohini/)gist.github.com (https://www.centurylawfirm.in/blog/frequently-asked-questions-in-cheque-bounce-cases/)gist.github.com (https://www.centurylawfirm.in/blog/criminal-lawyer-in-delhi-2/)gist.github.com (https://www.centurylawfirm.in/blog/divorce-lawyer-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/regular-bail-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/best-law-firm-in-delhi-2/)gist.github.com (https://www.centurylawfirm.in/blog/law-firm-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/civil-lawyer-in-new-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/top-10-lawyers-in-rohini/)gist.github.com (https://www.centurylawfirm.in/blog/criminal-lawyer-in-rohini/)gist.github.com (https://www.centurylawfirm.in/blog/top-10-lawyers-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/criminal-lawyer/)gist.github.com (https://www.centurylawfirm.in/blog/civil-case-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/matrimonial-case-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/civil-case-in-delhi-2/)gist.github.com (https://www.centurylawfirm.in/blog/lawyer-for-drt-in-rohini/)gist.github.com (https://www.centurylawfirm.in/blog/court-marriage/)gist.github.com (https://www.centurylawfirm.in/blog/criminal-lawyer-in-rohini-2/)gist.github.com (https://www.centurylawfirm.in/blog/nri-lawyer-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/property-lawyer-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/advocate-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/bail-matter-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/bail-in-rape-case-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/bail-matters/)gist.github.com (https://www.centurylawfirm.in/blog/anticipatory-bail/)gist.github.com (https://www.centurylawfirm.in/blog/divorce-lawyer-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/divorce-lawyer-in-rohini-2/)gist.github.com (https://www.centurylawfirm.in/blog/divorce-case-in-rohini/)gist.github.com (https://www.centurylawfirm.in/blog/divorce-case/)gist.github.com (https://www.centurylawfirm.in/blog/divorce-cases/)gist.github.com
(https://www.centurylawfirm.in/blog/happy-dhanteras-2021/)gist.github.com (https://www.centurylawfirm.in/blog/happy-diwali-2021/)gist.github.com (https://www.centurylawfirm.in/blog/happy-new-year-2022/)gist.github.com (https://www.centurylawfirm.in/blog/happy-republic-day-2022/)gist.github.com (https://www.centurylawfirm.in/blog/mutual-divorce/)gist.github.com (https://www.centurylawfirm.in/blog/best-lawyer-for-property-dispute-cases/)gist.github.com (https://www.centurylawfirm.in/blog/happy-holi-2022/)gist.github.com (https://www.centurylawfirm.in/blog/lawyer-for-fir-quashing-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/bail-in-criminal-case-in-delhi-2/)gist.github.com (https://www.centurylawfirm.in/blog/matrimonial-dispute-lawyer-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/lawyer-for-cheque-bounce-case-in-rohini/)gist.github.com (https://www.centurylawfirm.in/blog/best-lawyer-for-criminal-case/)gist.github.com (https://www.centurylawfirm.in/blog/latest-legal-awareness-videos-may-2022/)gist.github.com (https://www.centurylawfirm.in/blog/advocate-in-rohini-courts-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/advocate-in-karkardooma-court/)gist.github.com (https://www.centurylawfirm.in/blog/advocate-for-accident-claim-cases/)gist.github.com (https://www.centurylawfirm.in/blog/marriage-under-special-marriage-act-can-be-registered-through-video-conferencing-supreme-court-of-india/)gist.github.com (https://www.centurylawfirm.in/blog/maintenance-welfare-of-parents-senior-citizens/)gist.github.com (https://www.centurylawfirm.in/blog/arbitration-latest-supreme-court-judgement/)gist.github.com (https://www.centurylawfirm.in/blog/matrimonial-dispute-lawyer-in-rohini/)gist.github.com (https://www.centurylawfirm.in/blog/bail-in-376-rape-case-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/lawyer-for-civil-case-in-delhi-2/)gist.github.com (https://www.centurylawfirm.in/blog/lawyer-for-civil-case-in-tis-hazari-court/)gist.github.com (https://www.centurylawfirm.in/blog/lease-hold-to-free-hold-conversion/)gist.github.com (https://www.centurylawfirm.in/blog/latest-legal-awareness-videos-december-2021/)gist.github.com (https://www.centurylawfirm.in/blog/latest-legal-awareness-videos-january-2022/)gist.github.com (https://www.centurylawfirm.in/blog/cheque-bounce-case-latest-sc-guidelines-2021/)gist.github.com (https://www.centurylawfirm.in/blog/bail-in-criminal-case-in-delhi/)gist.github.com (https://www.centurylawfirm.in/blog/latest-legal-awareness-videos-february-2022/)gist.github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC