CMS 变得简单:使用 mysql_select_db($dbname);把一切搞乱

发布于 2024-10-31 02:15:44 字数 500 浏览 0 评论 0原文

你好,我对 cms 很陌生,很简单,我偶然发现了一个超出我范围的问题,我的 coad 是,

<?php

$dbh = 'localhost';
$dbu = 'root';
$dbp = '';

$connect = mysql_connect($dbh, $dbu, $dbp) or die ('Error connecting to mysql');

$yatzi = 'myposts';
mysql_select_db($yatzi);

echo "hello";
?>

我通过用户定义的标签使用它来导入 php 文件,问题是每次我加载此页面时都会弹出一个错误,说:

string(61) “Smarty 错误:无法读取资源:“globalcontent:footer”” string(61) “Smarty 错误:无法读取资源:“globalcontent:footer””

一切都变得一团糟,我真的不知道是什么正在发生,有人可以帮助我吗,谢谢...

hi im fairly new to cms made simple and ive stumbled upon a problem thats beyond me, my coad is

<?php

$dbh = 'localhost';
$dbu = 'root';
$dbp = '';

$connect = mysql_connect($dbh, $dbu, $dbp) or die ('Error connecting to mysql');

$yatzi = 'myposts';
mysql_select_db($yatzi);

echo "hello";
?>

and im using this through a user defined tag to import a php file, the proble is that everytime i load this page an error pops up saying:

string(61) "Smarty error: unable to read resource: "globalcontent:footer"" string(61) "Smarty error: unable to read resource: "globalcontent:footer""

and everything gets messedup, i seriously have no idead what is going on, can anybody please help me,, thnks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场信仰旅途 2024-11-07 02:15:44

如果此连接是到同一个数据库服务器,则问题可能是您覆盖了连接资源,因此您的 CMS 无法从数据库中提取任何内容。

这是因为默认情况下 PHP 会检测到您已经打开了一个连接,如果它们共享相同的参数,则返回该连接。您可以通过强制新连接来覆盖此行为:

$connect = mysql_connect($dbh, $dbu, $dbp, true);

然后,在使用此服务器时,您需要确保始终指定要使用的链接:

mysql_select_db($yatzi, $connect);

mysql_query($query, $connect);
// etc...

其他可能的问题可能是您的代码位于旧位置(例如直接在 Smarty 模板中)文件周围没有特殊的 php 转义标签),或者问题根本与您的代码无关,而是您的 CMS 安装或自定义出现了问题。

If this connection is to the same db server the issue could be that youre overwriting the connection resource and thus your CMS cant pull anything form the db.

This would be because by default PHP will detect that you already have a connection open and return that one if they share the same parameters. You can override this behavior by forcing a new connection:

$connect = mysql_connect($dbh, $dbu, $dbp, true);

Then when using this server you need to make sure you always specify which link to use:

mysql_select_db($yatzi, $connect);

mysql_query($query, $connect);
// etc...

Ohter possible issues might be that you have the code in the worng place (like directly in a Smarty template file without the special php escape tags surrounding it), or that the problem isnt related to your code at all and something is up with your CMS installation or customization.

孤独难免 2024-11-07 02:15:44
<?php

$dbh = 'localhost';
$dbu = 'root';
$dbp = '';
$yatzi = 'myposts';

$connect = mysqli_connect($dbh, $dbu, $dbp,$yatzi) or die ('Error connecting to mysql');

echo "hello";
?>
<?php

$dbh = 'localhost';
$dbu = 'root';
$dbp = '';
$yatzi = 'myposts';

$connect = mysqli_connect($dbh, $dbu, $dbp,$yatzi) or die ('Error connecting to mysql');

echo "hello";
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文