On 20.08.2014 12:46, Michael Wallner wrote:
> On 20/08/14 11:12, Marc Bennewitz wrote:>
>>
>> On 18.08.2014 17:43, Johannes Schlüter wrote:
>>> On Mon, 2014-08-18 at 17:30 +0200, Johannes Schlüter wrote:
>>>>     foreach ($db->query("SELECT id, title FROM entries") as $row) {
>>>>         echo "<tr><td";
>>>>         if ($row[0] == $_GET['highlight_id']) {
>>>>             echo " background='#ff0000'";
>>>>         }
>>>>         echo ">".htmlentities($row[1])."</td></tr>";
>>>>     }
>>>>
>>>> will suddenly fail. How wonderful! (irony)
>>>
>>> Just to make this more fun: Assume $db is PDO then the behavior will
>>> depend on the driver (and for some drivers even at the configuration,
>>> i.e. setting of PDO::ATTR_EMULATE_PREPARES with MySQL) what will happen.
>>
>> I don't understand exactly what you mean here. This RFC has nothing todo
>> with DB layer and PDO.
>>
>> Do you have any example where a DB returns integers differently?
> 
> php -r '$p = new PDO("mysql:user=root"); \
>   $s=$p->prepare("SELECT 1"); $s->execute(); \
>   var_dump($s->fetchAll()); \
>   $p->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); \
>   $s=$p->prepare("SELECT 1"); $s->execute(); \
>   var_dump($s->fetchAll());'
> 
> array(1) {
>   [0]=>
>   array(2) {
>     [1]=>
>     string(1) "1"
>     [2]=>
>     string(1) "1"
>   }
> }
> array(1) {
>   [0]=>
>   array(2) {
>     [1]=>
>     int(1)
>     [2]=>
>     int(1)
>   }
> }

Thank's for the explanation, but this is nothing that runs into issues
because:
- In case 1 the result number will be a string "1" that is equal with
another string of "1". Only if "1" will be compared to something like
"01", " 1", "0x1" the result will no longer be the same.
- In case 2 the DB layer already returns an integer and on comparing
this to a string the string will be converted to an integer, too -
nothing changed here by the RFC

To make the example of Johannes fail the DB layer have to return the
integer as string but not formed in a standard human way.

Marc

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to