txrandom Posted February 19, 2009 Share Posted February 19, 2009 $departmentRow = $departmentTable->fetchRow(array("department = ?" => $department)); Let's say there is an off chance $department may be null. Doing this with Zend Framework throws a 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' Is there any way to allow $department to be null? Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 19, 2009 Share Posted February 19, 2009 What would the point of that be? If the $department has no value you will not find any rows, so there is no point in doing the query. You should simply check for that and bypass the query altogether. If you really want to search for NULL (which should be avoided in my opinion) then the clause required is WHERE column IS NULL, so at minimum the string passed would probably need to be 'department IS NULL' rather than your array with bind variable. Quote Link to comment Share on other sites More sharing options...
txrandom Posted February 19, 2009 Author Share Posted February 19, 2009 That was a bad example: $slotRow = $slotTable->fetchRow(array("locationId = ?" => $locationRow->locationId, "timeId = ?" => $timeRow->timeId, "days = ?" => $days)); I'm using this for a data scrubber. I don't want to replicate data, so I need to make sure it's not already in there. For example, a slot may have the time and day fields filled, but this slot may not have a location. The location should be null since it doesn't have one. Well what if there is another slot with the same time and day, but actually has a location? I need to make sure I check whether that locationId is null. Does that make sense? Do you think there is a better approach to this? Quote Link to comment Share on other sites More sharing options...
txrandom Posted February 19, 2009 Author Share Posted February 19, 2009 Well I think I found a work around. I'm already detecting to see if the valid is null. I'm just going to change the "locationId = ?" to a variable and have the other option be "locationId IS NULL" That way it doesn't even matter if the parameter is null since it won't be binding it anyways. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.