1 # void pq\Connection::setConverter(pq\Converter $converter)
3 Set a data type converter.
7 * pq\Converter $converter
8 An instance implementing pq\Converter.
12 * pq\Exception\InvalidArgumentException
13 * pq\Exception\BadMethodCallException
19 class HStoreConverter implements pq\Converter
23 function __construct(pq\Types $types) {
24 $this->oids = [$types["hstore"]->oid];
27 function convertTypes() {
31 function convertFromString($string) {
32 return eval("return [$string];");
35 function convertToString($data) {
37 foreach ($data as $k => $v) {
39 $string .= sprintf("\"%s\"=>\"%s\",", addslashes($k), addslashes($v));
41 $string .= sprintf("\"%s\"=>NULL,", addslashes($k));
47 $connection = new pq\Connection;
48 $types = new pq\Types($connection);
50 $connection->setConverter(new HStoreConverter($types));
52 $result = $connection->execParams("SELECT \$1", [
62 var_dump(current($result->fetchAll()));