PHP的多个数据库问题 [英] php multiple databases issue

查看:84
本文介绍了PHP的多个数据库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了以下两个数据库连接

I've set two database conections as below

$con1 = mysql_connect("localhost", "root", "pwd") or die (mysql_error());

$con2 = mysql_connect("localhost", "wordpress", "pwd", true) or die(mysql_error());

mysql_select_db("lab_ancp", $con1) or die(mysql_error());   
mysql_select_db("wordpress",$con2) or die(mysql_error());

效果很好

因此,我在这样的页面上进行了一些查询:

so then i do some queries on a page like this:

$sql="select unome from associado where uid=$uid";
    $result=mysql_query($sql,$con1) or die(mysql_error());

它工作正常,之后我再次进行第二次查询:

and it works fine, after that i do a second query like this:

$sql="select ID, post_content, post_title, post_excerpt, meta_value
                    from wp_posts join (
                        select post_id, meta_value 
                        from wp_postmeta 
                            join (
                                select post_id from wp_postmeta
                                where meta_key='destaque' and meta_value='s'
                            )as t1 using(post_id)
                        where meta_key='pft_widescreen'
                    ) as t2 on (wp_posts.ID=t2.post_id)
                ORDER BY RAND() LIMIT 1";
            //echo $sql . "<br />";
            $row=mysql_fetch_assoc(mysql_query($sql,$con2)) or die(mysql_error());

一切都很好,但是然后...

and again everything is just fine, but then....

$sql="select * from eventos where edatade>='$hoje' or edataate>='$hoje'";
            $result=mysql_query($sql, $con1) or die (mysql_error());

给出此错误:

**

SELECT命令拒绝给用户 表的'wordpress'@'localhost' 'eventos'

SELECT command denied to user 'wordpress'@'localhost' for table 'eventos'

**

推荐答案

好吧

解决了.

不要问我原因,但是我试图更改前两行的顺序,即在$ con1之前放置$ con2,查询现在可以正常工作.

Don't askme the reason but i've tried to change the order in the first two roww, i.e put $con2 before $con1 and the queries now simply work fine.

我怀疑..."true"参数与此有关.

I suspect that the ..."true" parameter has something to do with that.

谢谢.

这篇关于PHP的多个数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆