mysql_close():5不是C语言中的有效MySQL-Link资源:第4行的\wamp \ www!包括\ footer.php [英] mysql_close(): 5 is not a valid MySQL-Link resource in C:\wamp\www\Includes\footer.php on line 4

查看:212
本文介绍了mysql_close():5不是C语言中的有效MySQL-Link资源:第4行的\wamp \ www!包括\ footer.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Everyth工作正常,它只是决定停止工作,它毁了我的整个项目,我处于停滞状态。

Everyth worked fine, it just decided to stop working and it ruined my whole project and Im at standstill.

这是错误:


mysql_close():5不是
中有效的MySQL-Link资源C:\ wamp \\\\Includes \ footer.php on第4行

mysql_close(): 5 is not a valid MySQL-Link resource in C:\wamp\www\Includes\footer.php on line 4

这是 footer.php

<?php
//close connection
if (isset($dbh)); {
    mysql_close($dbh);
}
?>

这是 connect.php


This is connect.php

//set constants
require("quick.php");

//database connection
$dbh = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$dbh) {  //check connection
        die("Cannot conect! to database ");
    }   

//selecting database
$db_select = mysql_select_db(DB_NAME, $dbh);
if (!$db_select) { //check connection
        die("Cannot connect to database ");
    }
?>

基本上每当我尝试退出mysql时,此错误都会显示。
不久前它一切正常。

Basically whenever I try to quit mysql this error shows. And it all worked fine not long ago.

推荐答案

在某个地方,在你的页面中,有一个赋值放置 $ dbh = 5; ,它会覆盖您的数据库连接。这是导致错误的原因。在数据库开头和页脚之间搜索该变量的任何分配,你就发现了问题。

Somewhere, within your page, there is an assignment that puts $dbh = 5; that overrides your database connection. That is the cause for the error. Search for any assignments to that variable between your database opening and your footer, and you've found your problem.

注意:我不会那个担心连接会像其他一些评论者一样在这里打开,因为如果它不是一个持久的连接,那么无论如何它将在脚本结束时关闭,所以我不知道看看这将如何破坏整个项目。您的代码尝试在页脚处关闭它,这与让它自己关闭没有多大区别。来自手册

Note: I wouldn't be that worried about the connection being open as some other commenters here, since if it's not a persistant connection, it will anyway be closed at the end of the script, so I don't see how that would be ruining your whole project. Your code tries to close it at the footer which is not much different than letting it close itself. From the manual:


通常不需要使用mysql_close(),因为在脚本执行结束时会自动关闭非持久性打开的
链接。
另请参见释放资源

这篇关于mysql_close():5不是C语言中的有效MySQL-Link资源:第4行的\wamp \ www!包括\ footer.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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