Unix Technical Forum

PHP and Postgres arrays

This is a discussion on PHP and Postgres arrays within the Pgsql General forums, part of the PostgreSQL category; --> Hello, I've been searching (not very thoroughly, but still) for a way to get Postgres arrays right into PHP ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:18 AM
Yannick Warnier
 
Posts: n/a
Default PHP and Postgres arrays

Hello,

I've been searching (not very thoroughly, but still) for a way to get
Postgres arrays right into PHP arrays, but it seems that the Postgres
driver simply doesn't allow that.

The only solution seems to use some user-defined functions[1] to split
the result of a query (a string) into a PHP array.

Some Perl-related readings [2] seem to say that Postgres actually
provides a string, loosing the possibility to get it as an array, but
these comments date back to 2005.

Any chance someone around here might tell me more about this and
possibly give me some better way to get those arrays than copy-pasting
the user-proposed PHP functions?

Thanks,

Yannick Warnier

[1] http://www.php.net/manual/en/ref.pgsql.php#58660
[2] http://www.perlmonks.org/?node_id=474518


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 12:18 AM
Ivan Sergio Borgonovo
 
Posts: n/a
Default Re: PHP and Postgres arrays

On Fri, 18 Jan 2008 23:01:09 +0100
Yannick Warnier <ywarnier@beeznest.org> wrote:

> Hello,


> I've been searching (not very thoroughly, but still) for a way to
> get Postgres arrays right into PHP arrays, but it seems that the
> Postgres driver simply doesn't allow that.


What about using a stored procedure to return the array as a joined
row?

--
Ivan Sergio Borgonovo
http://www.webthatworks.it


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 12:18 AM
Yannick Warnier
 
Posts: n/a
Default Re: PHP and Postgres arrays


Le vendredi 18 janvier 2008 à 23:10 +0100, Ivan Sergio Borgonovo a
écrit :
> On Fri, 18 Jan 2008 23:01:09 +0100
> Yannick Warnier <ywarnier@beeznest.org> wrote:
>
> > Hello,

>
> > I've been searching (not very thoroughly, but still) for a way to
> > get Postgres arrays right into PHP arrays, but it seems that the
> > Postgres driver simply doesn't allow that.

>
> What about using a stored procedure to return the array as a joined
> row?


I thought about it, but it's not very portable if you want to ship a PHP
application. But I admit I will fall back to that solution if I cannot
find any other (considering PostgreSQL might be the only open-source
database to offer in-fields arrays anyway).

Yannick


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 12:18 AM
Hannes Dorbath
 
Posts: n/a
Default Re: PHP and Postgres arrays

Yannick Warnier wrote:
> I thought about it, but it's not very portable if you want to ship a PHP
> application. But I admit I will fall back to that solution if I cannot
> find any other (considering PostgreSQL might be the only open-source
> database to offer in-fields arrays anyway).


You can use the build in function array_to_string:
http://www.postgresql.org/docs/8.3/s...ons-array.html


--
Best regards,
Hannes Dorbath
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 12:18 AM
brian
 
Posts: n/a
Default Re: PHP and Postgres arrays

Hannes Dorbath wrote:
> Yannick Warnier wrote:
>> I thought about it, but it's not very portable if you want to ship a PHP
>> application. But I admit I will fall back to that solution if I cannot
>> find any other (considering PostgreSQL might be the only open-source
>> database to offer in-fields arrays anyway).

>
> You can use the build in function array_to_string:
> http://www.postgresql.org/docs/8.3/s...ons-array.html
>


Then use implode(YOUR_DELIMITER, YOUR_STRING) to get an array.

Another solution would be to use the MDB2 (or similar) PEAR wrapper.

b

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:14 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com