Note Submitter: xcojack at gmail dot com
----
Here is an example how to convert php array to postgresql anyarray type:
<?php
/**
* @author Przemysław Czekaj <[email protected]>
* @link http://www.cojack.pl
*/
function phpArrayToPg(array $phpArray, $inner_glue = ',') {
foreach($phpArray as $key => $value) {
if(is_array($value)) {
$output[$key] = "{".phpArrayToPg($value, $inner_glue)."}";
}
else {
if(!(int)$value)
$output[$key] = '"'.$value.'"';
else
$output[$key] = (int)$value;
}
}
return implode($inner_glue,$output);
}
?>
Usage?
Some array:
<?php
$a = array(
array(
1,
'cgusia',
),
array(
6,
2
),
array(
'oruflik',
'jrzmiot'
)
);
echo "E'{".phpArrayToPg($a)."}'";
?>
the above example will output:
E'{{1,"cgusia"},{6,2},{"oruflik","jrzmiot"}}'
How you will secure this part of data when you will send them to the sql server it's only your problem.
Cast them and it works awesome ;)
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.