ID:               46249
 Updated by:       [EMAIL PROTECTED]
 Reported By:      hswong3i at gmail dot com
-Status:           Open
+Status:           Closed
 Bug Type:         PDO related
 Operating System: Debian
 PHP Version:      5.2.6
 Assigned To:      felipe
 New Comment:

You aren't working with real NULL, but with a "empty resource". It's
exaclty what happens to fwrite($fp, '') too.

Only using the code below you will get the NULL as expect:
$blob = null;
$stmt->bindParam(':blob1', $blob, PDO::PARAM_LOB);


Thanks.


Previous Comments:
------------------------------------------------------------------------

[2008-10-13 02:32:42] hswong3i at gmail dot com

It is now result as:

string(23) "Test normal BLOB insert"

string(15) "This is�a test."

string(15) "This is�a test."

bool(true)

string(21) "Test NULL BLOB insert"

NULL

string(0) ""

bool(false)

string(22) "Test empty BLOB insert"

string(0) ""

string(0) ""

bool(true)

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

[2008-10-13 02:31:42] hswong3i at gmail dot com

Bug still exists, but preform in another way... Please try the
following code snippet:

<?php

function _var_dump($msg) {
  print("<code><pre>");
  var_dump($msg);
  print("</pre></code>");
}

function db_insert($sql, $data) {
  global $active_db;
  $stmt = $active_db->prepare($sql);
  $blob = fopen('php://memory', 'a');
  fwrite($blob, $data);
  rewind($blob);
  $stmt->bindParam(':blob1', $blob, PDO::PARAM_LOB);
  $stmt->execute();
  $id = $active_db->lastInsertId('test_one_blob_id_seq');
  return $id;
}

function db_select($sql, $id) {
  global $active_db;
  $sql = 'SELECT * FROM "test_one_blob" WHERE "id" = :id';
  $stmt = $active_db->prepare($sql);
  $stmt->bindParam(':id', $id);
  $stmt->execute();
  return $stmt->fetch(PDO::FETCH_ASSOC);
}

$active_db = new PDO('pgsql:host=localhost dbname=DRUPAL_7', 'root',
'CHANGE', array(PDO::ATTR_STRINGIFY_FETCHES => TRUE));

// Test normal BLOB insert
$data = "This is\000a test.";
$id = db_insert('INSERT INTO "test_one_blob" ("blob1") VALUES
(:blob1)', $data);
$return = db_select('SELECT * FROM "test_one_blob" WHERE "id" = :id',
$id);
_var_dump("Test normal BLOB insert");
_var_dump($data);
_var_dump($return['blob1']);
_var_dump($data === $return['blob1']);

// Test NULL BLOB insert
$data = NULL;
$id = db_insert('INSERT INTO "test_one_blob" ("blob1") VALUES
(:blob1)', $data);
$return = db_select('SELECT * FROM "test_one_blob" WHERE "id" = :id',
$id);
_var_dump("Test NULL BLOB insert");
_var_dump($data);
_var_dump($return['blob1']);
_var_dump($data === $return['blob1']);

// Test empty BLOB insert
$data = "";
$id = db_insert('INSERT INTO "test_one_blob" ("blob1") VALUES
(:blob1)', $data);
$return = db_select('SELECT * FROM "test_one_blob" WHERE "id" = :id',
$id);
_var_dump("Test empty BLOB insert");
_var_dump($data);
_var_dump($return['blob1']);
_var_dump($data === $return['blob1']);

?>

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

[2008-10-12 17:44:50] hswong3i at gmail dot com

@felipe: Yes I did. I give a compare with cvs.php.net log message, and
check if my PHP package coming with the fix. Fix is already included,
#46249 is fixed but than buggy for #46274 as mentioned :S

I try both PHP in CLI and Apache2.2. BLOB INSERT/UPDATE are successful
in both cases, but fetching NULL and empty string are both buggy...

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

[2008-10-12 16:51:05] [EMAIL PROTECTED]

Do you have tried after 13:03:31 2008 UTC? I've commited a complete fix
to these issue in this time.

Thanks.

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

[2008-10-12 16:39:57] hswong3i at gmail dot com

I try for both PHP5.2 and 5.3 from http://snaps.php.net/ (they both
coming with the fix). They are now able to handle NULL and empty string
BLOB INSERT/UPDATE. Thanks for the work.

BTW, it is now generate another issue that should belongs to
http://bugs.php.net/bug.php?id=46274. Whenever fetching NULL or empty
BLOB content from DB apache will crash with Segmentation fault. Maybe we
still need some love for that :S

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/46249

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

Reply via email to