查询期间失去与 MySQL 服务器的连接 - PHP、MySQL

发布于 2024-09-13 11:04:48 字数 773 浏览 10 评论 0原文

我有这个 php 代码,这些文件托管在另一台服务器和数据库上,其中

$hostname_xxx = "xxxdb.db.234141.mysqldbhosted.com";
$database_xxx = "xx11xx";
$username_xxx = "xx11xx";
$password_xxx = "xx332211xx";
$shasown = mysql_pconnect($hostname_xxx, $username_xxx, $password_xxx) or trigger_error(mysql_error(),E_USER_ERROR); 


$your_ip = $_SERVER['REMOTE_ADDR'];


echo $your_ip;



$insertSQL1 = "INSERT INTO  table (users_ip) VALUES ('$your_ip)";
mysql_select_db($database_xxx, $xxx);
$Result21 = mysql_query($insertSQL1, $xxx) or die(mysql_error());

我收到的错误是

警告:mysql_pconnect()[function.mysql-pconnect]:查询期间丢失与MySQL服务器的连接在 /domains/4444.com/html/55.php 第 8 行

致命错误:在 /domains/4444.com/html/55.php 第 8 行查询期间丢失与 MySQL 服务器的连接

谢谢 让

I have this php code, the files are hosted on another server and db else where

$hostname_xxx = "xxxdb.db.234141.mysqldbhosted.com";
$database_xxx = "xx11xx";
$username_xxx = "xx11xx";
$password_xxx = "xx332211xx";
$shasown = mysql_pconnect($hostname_xxx, $username_xxx, $password_xxx) or trigger_error(mysql_error(),E_USER_ERROR); 


$your_ip = $_SERVER['REMOTE_ADDR'];


echo $your_ip;



$insertSQL1 = "INSERT INTO  table (users_ip) VALUES ('$your_ip)";
mysql_select_db($database_xxx, $xxx);
$Result21 = mysql_query($insertSQL1, $xxx) or die(mysql_error());

The error I am getting is

Warning: mysql_pconnect() [function.mysql-pconnect]: Lost connection to MySQL server during query in /domains/4444.com/html/55.php on line 8

Fatal error: Lost connection to MySQL server during query in /domains/4444.com/html/55.php on line 8

Thanks
Jean

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

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

发布评论

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

评论(1

我们的影子 2024-09-20 11:04:48

mysql_pconnect() 创建到数据库的持久连接,而 mysql_connect() 则不会。如果您要创建持久连接,则在整个会话中只需要连接一次,因此如果您多次创建持久连接,这可能就是原因。

在共享服务器上,可能值得尝试 mysql_connect() 而不是 mysql_pconnect(),看看这是否可以解决当前的问题。另外,在您的代码中,您有:

$Result21 = mysql_query($insertSQL1, $xxx) or die(mysql_error());

但应该是:

$Result21 = mysql_query($insertSQL1, $shasown) or die(mysql_error());

因为 $xxx 从来都不是连接变量,但 $shasown 是。

我个人喜欢使用 mysqli_connect() 因为我发现它更快一点。

mysql_pconnect() creates a persistent connection to the database, whereas mysql_connect() does not. IF you are creating a persistent connection, you need only connect once throughout your session, so if you're creating a persistent connection more than once this may be the cause.

On shared servers it may be worth trying mysql_connect() over mysql_pconnect() and see if this corrects the issue at hand. Also, in your code you have:

$Result21 = mysql_query($insertSQL1, $xxx) or die(mysql_error());

But should be:

$Result21 = mysql_query($insertSQL1, $shasown) or die(mysql_error());

because $xxx was never a connection variable but $shasown is.

Personally I like to use mysqli_connect() as I find it to be a little faster.

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