note 100131 modified in pdo.quote by danbrown
| From: | danbrown@php.net | Date: | Mon, 27 Sep 2010 16:32:04 +0000 |
| Subject: | note 100131 modified in pdo.quote by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172739@lists.php.net to get a copy of this message | ||
For those of you who do want to have null returned as NULL, it is fairly easy to add.
<?php
class Real_PDO extends PDO {
public function quote($value, $parameter_type = PDO::PARAM_STR ) {
if( is_null($value) ) {
return "NULL";
}
return parent::quote($value, $parameter_type);
}
}
?>
then all you have to do is change your creation of the PDO object to this new class, and you
shouldn't have to change any other function calls. The nice thing about this method is that
you can override any PDO function or add your own. IMO, PDO should natively handle this, as there
is a difference in databases between NULL and an empty string(''), the quoting of numeric
values is another issue altogether.
--was--
For those of you who do want to have null returned as NULL, it is fairly easy to add.
class Real_PDO extends PDO {
public function quote($value, $parameter_type = PDO::PARAM_STR ) {
if( is_null($value) ) {
return "NULL";
}
return parent::quote($value, $parameter_type);
}
}
then all you have to do is change your creation of the PDO object to this new class, and you
shouldn't have to change any other function calls. The nice thing about this method is that
you can override any PDO function or add your own. IMO, PDO should natively handle this, as there
is a difference in databases between NULL and an empty string(''), the quoting of numeric
values is another issue altogether.
http://php.net/manual/en/pdo.quote.php