[Solar-talk] bounding zero
Paul M Jones
pmjones at ciaweb.net
Mon Mar 12 10:13:38 PDT 2007
On Mar 12, 2007, at 12:08 PM, Rodrigo Moraes wrote:
> On 3/12/07, Rodrigo Moraes wrote:
>> Hi.
>> I'm in doubt about the cleanest way to bound a variable that can be 0
>> (integer zero). For example:
>>
>> $select = Solar::factory('Solar_Sql_Select');
>> $res = $select->from('my_table', 'my_column')
>> ->where('my_column = ?', $x)
>> ->fetch('value');
>>
>> If $x = 0, a exception is thrown, but if $x = '0' it is not. Is it
>> really necessary to quote the zero or cast it to a string? I thought
>> this could be a bug in Solar_Sql_Select::where(), on these lines:
>
> Addind more info. The exception is:
>
> Uncaught exception 'Solar_Sql_Adapter_Exception_QueryFailed'
> class::code 'Tipos_Sql_Adapter_Mysql::ERR_QUERY_FAILED' with message
> 'ERR_QUERY_FAILED' information array ( 'pdo_code' => 'HY093',
> 'pdo_text' => 'SQLSTATE[HY093]: Invalid parameter number: no
> parameters were bound', [...]
>
> in Solar_Sql_Select::where():
>
> 1. when the bound parameter is integer 0:
>
> var_dump($val != SOLAR_IGNORE_PARAM);
> result: false
>
> 1. when the bound parameter is string 0:
>
> var_dump($val != SOLAR_IGNORE_PARAM);
> result: true
>
> So int(0) is not allowed to be bound. :-|
Can you tell if this is a problem with Solar_Sql, or if it is with PDO?
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list