From:             bugzilla at lourdas dot name
Operating system: Gentoo Linux
PHP version:      5.3.17
Package:          PDO related
Bug Type:         Bug
Bug description:PDO::ATTR_ORACLE_NULLS not respected

Description:
------------
I use the latest stable version of the Yii PHP framework (v.1.1.12). I also
use the MySQL PDO driver to create a new model. The data model is taken
from a HTML form. For empty values, I get an empty string during POST. Some
of the empty values are meant to be used as foreign keys to a master table.
The corresponding MySQL database columns are nullable, so they can either
have NULL or the id of the referencing table (master). I have set the
nullConversion property of the CDbConnection class (see
http://www.yiiframework.com/doc/api/1.1/CDbConnection) which
correspondingly sets the PDO::ATTR_ORACLE_NULLS property as needed in order
to convert these empty string values to NULL before saving the model. I use
the PDO::NULL_EMPTY_STRING value in nullConversion property to do this,
however, no matter which PDO::ATTR_ORACLE_NULLS value I use, the result is
always the same. The empty strings are not converted to NULLs, so the row
insertion in MySQL fails because of foreign key constraint violation. Not
to mention that if I run the same query from the mysql client with the
corresponding empty string database columns converted to NULL, the
insertion works fine. I have already reported this as a bug to the Yii
repository (https://github.com/yiisoft/yii/issues/1442), however one of the
core developers explains that the framework simply sets the value of this
PDO property, so if the code does not work, this is a PDO bug, that's why
I'm opening this bug.

Test script:
---------------
In Yii's main configuration file:

'db'=>array( // this is an instance of the CDbConnection class
        'connectionString' => 'mysql:host=localhost;dbname=mydb',
        'emulatePrepare' => true,
        'username' => 'myuser',
        'password' => 'mypass',
        'charset' => 'utf8',
        'enableProfiling' => true,
        'enableParamLogging' => true,
        'nullConversion' => PDO::NULL_EMPTY_STRING,
),

and in the controller class:

if (isset($_POST['Visitors'])) { // get values from form
        $visitor->attributes = $_POST['Visitors'];
        $visitor->date_registered = new CDbExpression('CURDATE()');
        if ($visitor->save())  // save the database model, instance of
CActiveRecord
                Yii::app()->user->setFlash('userCreated', 'You have successfully
joined.');
        else {
                Yii::app()->user->setFlash('userCreated', 'There was a problem 
creating
your user account.');
        }
}


Expected result:
----------------
Since some database columns are nullable, the empty strings should be
converted by the PDO driver to NULLs, so that the insert would work.
Instead, I get a foreign key constraint error, since the driver tries to
insert empty strings at these database columns, instead of NULLs, which are
allowed.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=63124&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63124&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63124&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63124&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63124&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63124&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63124&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63124&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63124&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63124&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63124&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63124&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63124&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63124&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63124&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63124&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63124&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63124&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63124&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63124&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63124&r=mysqlcfg

Reply via email to