php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59948 Empty string inserted into varchar field fills with blanks
Submitted: 2011-09-12 11:02 UTC Modified: 2012-01-17 09:59 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: martin dot hieden at hieden dot at Assigned:
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.2.17 OS: i5/OS V6R1
Private report: No CVE-ID: None
 [2011-09-12 11:02 UTC] martin dot hieden at hieden dot at
Description:
------------
When trying to insert an empty string into a varchar field, the field is filled with blanks, i.e. the length isn't set to zero. This happens regardless of allowing null for this field or not.

Reproduce code:
---------------
Assuming there's the table 'blank_tbl' in library 'blank' containing of a single varchar field with maximum length 10.
A          R PHPS
A            BLANK_FLD     10          VARLEN

<?php
$dbname = '*';
$username = '*';
$password = '*';

if (($database = db2_connect($dbname, $username, $password)) === false) die(db2_conn_errormsg());

$sql = <<<EOT
INSERT INTO blank.blank_tbl(blank_fld)
VALUES (?)
EOT;

$data = array('');

if (($stmt = db2_prepare($database, $sql)) === false) print_r(db2_stmt_errormsg());

if ($stmt && db2_execute($stmt, $data) === false) print_r(db2_stmt_errormsg($stmt));

db2_close($database);
?>

Expected result:
----------------
A row should be inserted into the table, with the single field beeing an empty string.

Actual result:
--------------
The row is inserted, but the string consists of blanks, filled up to the maximum length.

Taking a look at the data directly (aka PDM) shows these hex contents:
004444444444
0A0000000000

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-16 05:43 UTC] bestgen at us dot ibm dot com
Martin, This is a bug in the prepare/execute path. A fix will be provided through normal channels. As a circumvention the execdirect path does work with zero length strings.
 [2012-01-17 09:59 UTC] martin dot hieden at hieden dot at
-Status: Open +Status: Closed
 [2012-01-17 09:59 UTC] martin dot hieden at hieden dot at
Thanks Rob, your fix is working.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC