Using schemas in ZF2 / Db

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using schemas in ZF2 / Db

rodo
This post has NOT been accepted by the mailing list yet.

Hi,

I have defined tables in schemas in postgres but I can't read them with
Zend/Db (ZF2).  I define the table like "schema.table" and when ZF try to
read it doesn't find it.

select "schema.table".* from "schema.table"

In postgres, when I remove the quotes it works fine.


class ClientTable extends AbstractTableGateway
{
    protected $table = 'vip.clients';


"vip" is ths schema name.


How could indicate the schema, appart from the table name?


Thanks.

Rodolfo.

Reply | Threaded
Open this post in threaded view
|

Re: Using schemas in ZF2 / Db

speedrock
Heya,

I have exacly the same problem! In zf1 this was realy easy and straigforward bud zf2 it seems to be impossible.
One sollution that i came up with is using the postgres command to set the search path before executing any querys.

$statement = $adapter->query("SET search_path TO pdp;", 'execute');

After that postgres will always look in the "pdp" schema. Checkout thier manual (http://www.postgresql.org/docs/8.1/static/ddl-schemas.html)

However is still want to know if there is a way to specify the schema on query time or with the abstracttablegateway...

Greetz
rodo wrote
Hi,

I have defined tables in schemas in postgres but I can't read them with
Zend/Db (ZF2).  I define the table like "schema.table" and when ZF try to
read it doesn't find it.

select "schema.table".* from "schema.table"

In postgres, when I remove the quotes it works fine.


class ClientTable extends AbstractTableGateway
{
    protected $table = 'vip.clients';

"vip" is ths schema name.


How could indicate the schema, appart from the table name?


Thanks.

Rodolfo.
luk
Reply | Threaded
Open this post in threaded view
|

Re: Using schemas in ZF2 / Db

luk
speedrock wrote
I have exacly the same problem! In zf1 this was realy easy and straigforward bud zf2 it seems to be impossible.
One sollution that i came up with is using the postgres command to set the search path before executing any querys.

$statement = $adapter->query("SET search_path TO pdp;", 'execute');

After that postgres will always look in the "pdp" schema. Checkout thier manual (http://www.postgresql.org/docs/8.1/static/ddl-schemas.html)

However is still want to know if there is a way to specify the schema on query time or with the abstracttablegateway...
Hi, by digging inside some of the Zend\Db Postgres stuff I can tell you that there is no support for multiple schemas. I don't know either if there will be at some point. When an Adapter is being initialized it is always selecting a CURRENT_SCHEMA. I recommend you to use Zend\Db Adapter to run Postgres procedures and there you can run queries against multiple schemas on your DB level.
Cheers, -- Luke Mierzwa