php,mysql服务器不见了

编程入门 行业动态 更新时间:2024-10-25 02:26:26
本文介绍了php,mysql服务器不见了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

什么是错,当您在查询之前连接到LINE上的数据库时,您仍然收到"MySQL服务器已消失"的信息吗?

What is wrong, when you connect to the DB on the LINE BEFORE THE QUERY, and you still get "MySQL server has gone away"?

检查此示例代码:

mysql_connect("localhost", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); $sql = mysql_query("SELECT id FROM db"); while ($data = mysql_fetch_assoc($sql)) { $ids[] = $data[id]; } foreach ($ids as $id) { $content = file_get_contents("www.id/?id=$id"); if (stristr($content, "the id is ok man")) { mysql_connect("localhost", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); mysql_query("UPDATE db SET status = 'OK' WHERE id = '$id'"); } }

mysql服务器不见了,我在foreach循环中得到了它. 顺便说一句,我需要在foreachloop中进行连接,因为它可能需要一段时间才能找到要更新的内容(例如1-2分钟),然后确定我将使mysql服务器消失.

mysql server is gone away, i get that in the foreach loop. BTW i need to connect in the foreachloop, because it may take along time before it finds something to update (like 1-2 minutes), and then for sure i will get mysql server has gone away.

推荐答案

我认为您的问题是该脚本可能在发送第一个UPDATE查询之前执行了很长时间.

I assume your issue is that the script may execute for a very long time before sending the first UPDATE query.

您应该检查myf中的wait_timeout值.您可以通过运行查询"SHOW VARIABLES;"来检查您的wait_timeout

You should check the wait_timeout value in myf. You can check your wait_timeout by running the query "SHOW VARIABLES;"

您也可以尝试编写一段代码来重新连接:

You can also try to piece of code to do a reconnect:

if (!mysql_ping ($conn)) { //here is the major trick, you have to close the connection (even though its not currently working) for it to recreate properly. mysql_close($conn); $conn = mysql_connect('localhost','user','pass'); mysql_select_db('db',$conn); }

结合您的代码将是:

mysql_connect("localhost", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); $sql = mysql_query("SELECT id FROM db"); while ($data = mysql_fetch_assoc($sql)) { if (!mysql_ping ()) { //here is the major trick, you have to close the connection (even though its not currently working) for it to recreate properly. mysql_close(); mysql_connect("localhost", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); } $ids[] = $data['id']; $content = file_get_contents("www.id/?id=$id"); if (stristr($content, "the id is ok man")) { mysql_query("UPDATE db SET status = 'OK' WHERE id = '$id'"); } }

更多推荐

php,mysql服务器不见了

本文发布于:2023-11-16 18:51:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不见了   服务器   php   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!