CMS 变得简单:使用 mysql_select_db($dbname);把一切搞乱
你好,我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果此连接是到同一个数据库服务器,则问题可能是您覆盖了连接资源,因此您的 CMS 无法从数据库中提取任何内容。
这是因为默认情况下 PHP 会检测到您已经打开了一个连接,如果它们共享相同的参数,则返回该连接。您可以通过强制新连接来覆盖此行为:
然后,在使用此服务器时,您需要确保始终指定要使用的链接:
其他可能的问题可能是您的代码位于旧位置(例如直接在 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:
Then when using this server you need to make sure you always specify which link to use:
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.