查询期间失去与 MySQL 服务器的连接 - PHP、MySQL
我有这个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mysql_pconnect() 创建到数据库的持久连接,而 mysql_connect() 则不会。如果您要创建持久连接,则在整个会话中只需要连接一次,因此如果您多次创建持久连接,这可能就是原因。
在共享服务器上,可能值得尝试 mysql_connect() 而不是 mysql_pconnect(),看看这是否可以解决当前的问题。另外,在您的代码中,您有:
但应该是:
因为 $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:
But should be:
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.