问题
我至今所做的一切
示例:
$user_id = select user_id fron user_table WHERE name=abc将$user_id传递给dbObject user_works db并获取用户ids。
$rent = select user_id,rent from rent_table WHERE user_id IN ( $user_ids )将$rent传递给定价数据库的dbObject,我想在php应用程序中这样做
有什么更好的方法吗。定价数据库真的很重?比如使用临时表等等。
发布于 2013-04-16 12:20:12
使用来自定价数据库连接的dblink
select r.*
from
dblink(
'dbname=user_works password=password user=user',
$$ select user_id from user_table where name = 'abc' $$
) as u(user_id int)
inner join
rent_table r on r.user_id = u.user_id您需要将dblink扩展创建为超级用户:
create extension dblink;或从远程数据库创建本地视图:
create view user_table as
select *
from
dblink(
'dbname=user_works password=password user=user',
$$ select user_id, name from user_table $$
) as t(user_id int, name text)
;现在查询它,因为它是本地的:
select * from user_table where name = 'abc';https://stackoverflow.com/questions/16036223
复制相似问题