Re: pdo: cannot send NULL values thru bound parameters.

From: Date: Thu, 24 Mar 2005 11:47:30 +0000
Subject: Re: pdo: cannot send NULL values thru bound parameters.
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-15579@lists.php.net to get a copy of this message
Am 24.03.2005 um 12:32 schrieb Jared Williams:
$stmt = $this->prepareStatement('insert into bla (name) values (:name)'); $name = NULL; var_dump($name); // $name is NULL $stmt->bindParam(':name', $name); var_dump($name); // $name is an empty string am i overlooking something obvious?
$stmt->bindParam(':name', $name, PDO_PARAM_NULL); Or $stmt->bindParam(':name', $name, is_null($name) ? PDO_PARAM_NULL : PDO_PARAM_STR); Is what I've been using, and works. http://pecl.php.net/bugs/bug.php?id=3391 was the original bug report I opened, that's since been fixed. Jared
i really think that is wrong: (a) NULL is a valid value for a string. (b) bindParam should not change the type of a passed in php-variable. my patch actually only "solves" (a) -- we should also fix (b). to do this we need to: - leave the php-var (zval) untouched in bindParam (except for bumping the refcount) - when we "need" the string value (during execute) we need to seperate and convert so that the original zval keeps its type. re, thies

« previous php.internals (#15579) next »