[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-bugs
Subject:    [DOC-BUGS] Doc #54618 [Opn]: bindValue always returns true
From:       johannes () php ! net
Date:       2011-05-26 12:42:45
Message-ID: 20110526124246.358DB14ACD () ez1 ! php ! net
[Download RAW message or body]

Edit report at http://bugs.php.net/bug.php?id=54618&edit=1

 ID:                 54618
 Updated by:         johannes@php.net
 Reported by:        jakub dot lopuszanski at nasza-klasa dot pl
 Summary:            bindValue always returns true
 Status:             Open
 Type:               Documentation Problem
 Package:            PDO related
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

PHP is a weakly typed language. Implicit casts happen all the time in
PHP. Other erros often can't be caught until the statement is executed
(either when the replacement is done with emulation, or when the data is
sent to the server with native PS)


Previous Comments:
------------------------------------------------------------------------
[2011-05-05 08:17:12] jakub dot lopuszanski at nasza-klasa dot pl

Is casting 'a' to integer sane?

------------------------------------------------------------------------
[2011-05-02 07:31:01] frozenfire@php.net

I passed this bug by the fine folks in ##php on Freenode, and TML
mentioned that 
by providing a PDO::PARAM_* type, you're likely causing casting
behaviour in the 
PHP engine.

I believe an error will only arise in the case that casting doesn't
provide a 
sane value.

Do you mind doing some tests to see if errors arise for "non-sane"
casting?

------------------------------------------------------------------------
[2011-04-28 09:06:16] jakub dot lopuszanski at nasza-klasa dot pl

Description:
------------
even if you
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); the
function bindValue (at least with MySQL driver) will not help you detect
any type errors, duplicated calls, or binding to wrong parameter.


Test script:
---------------
Bellow is a part of my PHPUnit tests that confirm this ( i guess you can
figure out that getSUT, gets system under tests, that is prepares a
query from PDO object connected to MySQL database):

<?php
 public function testBindValueAlwaysReturnsTrue(){
   $s = $this->getSUT("SELECT 1 FROM users WHERE id=:id");
   //this one is ok:
   $this->assertSame(true,$s->bindValue(':id',1,PDO::PARAM_INT));
   //this one is not ok at all, as '1' is not integer.
   //moreover we already bound id
   $this->assertSame(true,$s->bindValue(':id','1',PDO::PARAM_INT));
   //this is also bad to allow both :id and id
   $this->assertSame(true,$s->bindValue('id',1,PDO::PARAM_INT));
   //1 is not a string
   $this->assertSame(true,$s->bindValue('id',1,PDO::PARAM_STR));
   //'a' is not an integer
   $this->assertSame(true,$s->bindValue('id','a',PDO::PARAM_INT));
   //null is surely not an integer:
   $this->assertSame(true,$s->bindValue('id',null,PDO::PARAM_INT));
   //1 is not a null
   $this->assertSame(true,$s->bindValue('id',1,PDO::PARAM_NULL));
   //13 is not a valid type of parameter
   $this->assertSame(true,$s->bindValue(':id',1,13));
   //'atlantis' is not even mentioned in the SQL query string:
   $this->assertSame(true,$s->bindValue(':atlantis',1,PDO::PARAM_INT));
 }

?>

Expected result:
----------------
I would expect either more precise documentation which would list all
cases for which bindValue returns false (I could not find any), or
fixing the function, to return false in cases mentioned above.

Actual result:
--------------
function returns true whatever I do.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54618&edit=1

-- 
PHP Documentation Bugs Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic