dongqing6661 2011-04-12 15:43
浏览 52
已采纳

Wordpress在wordpress页面上搞乱我的db调用?

Hey, hows it going everyone? I am having database conflicts I was wanting some help with.

Basically, I have a header that pulls in a random database field. Nothing special. It is in my header in my template and works just fine on non WordPress pages.

$sql = "SELECT * FROM headerslogans ORDER BY RAND() LIMIT 1";
    $result = mysql_query($sql);
    while ($myrow = mysql_fetch_array($result)) {
    echo $myrow['slogan'];
};

I am using the same database, same user name, same password, etc. However, I get this error where the echo should be....

Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in <dir name>

So obviously the wordpress connection is "overwriting" the other (wordpress works flawlessly). BUT, I was also confused as to why it doesn't work, although it is connecting to the same database with same username and password.

Can anybody help me out on this?

UPDATE: Posted connection code

$x = mysql_connect($server,$dbuser,$dbpass,true) or die(mysql_error()); mysql_select_db($dbname,$x);

  • 写回答

2条回答 默认 最新

  • duanchensou8685 2011-04-12 15:48
    关注

    As you said, the connection is getting overwritten, is the database selection also getting over written? It's probable that actually mysql_select_db() is the thing screwing you over. Fix it by setting you your original connection as a variable, and referencing it in the offending mysql_* functions, eg:

    $dbcnct = mysql_connect(...);
    mysql_select_db('...', $dbcnct);
    mysql_query('...', $dbcnct);
    

    This shouldn't affect your current setup either.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?