【问题标题】:MySQL Server GoneMySQL 服务器不见了
【发布时间】:2015-07-21 11:33:32
【问题描述】:

我尝试将数据存储到数据库中。但我收到“MySQL 服务器消失”错误。谁能帮我找出我的错误?

其实这是基本的 PHP 爬虫之一。我是这个的初学者。所以帮帮我!!!

Connection.php:

<?php
$hostname_TestConnection = "******";
$database_TestConnection = "*******";
$username_TestConnection = "*******";
$password_TestConnection = "********";
$TestConnection = mysqli_connect($hostname_TestConnection, $username_TestConnection, $password_TestConnection) or trigger_error(mysqli_error($TestConnection),E_USER_ERROR); 
?>

索引.php:

<?php require_once('Connections/TestConnection.php');
include_once('simple_html_dom.php');  

ini_set('mysql.connect_timeout', -1);
ini_set('default_socket_timeout', -1);

if (!function_exists("GetSQLValueString")) {
 function GetSQLValueString($theValue, $theType,  $TestConnection, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ?  mysqli_real_escape_string($TestConnection, $theValue) :  mysqli_escape_string($TestConnection, $theValue);

switch ($theType) {
 case "text":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;    
 case "long":
 case "int":
   $theValue = ($theValue != "") ? intval($theValue) : "NULL";
   break;
 case "double":
   $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
   break;
 case "date":
   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
   break;
 case "defined":
   $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
   break;
 }
 return $theValue;
 }
}

$target_url = "***";
$html = new simple_html_dom();
$html_sub_page = new simple_html_dom();
$html->load_file($target_url);

//Declare elements {......}

//Retrieve latest ID from table {....}

//Main Page content {....}

//Sub Page content {....}

//Insert Into DB

if($flag == 1)
{
    for($i = 0 ; $i < $counter ; $i++)
    {

    $latestid ++;
    $guid .= $latestid;
    $post_name = $latestid.$post_name;

    $insertSQL = sprintf("INSERT INTO test_posts (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type,post_mine_type, comment_count) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($post_author, "int", $TestConnection),
                       GetSQLValueString($post_date, "date", $TestConnection),
                       GetSQLValueString($post_date_gmt, "date", $TestConnection),
                       GetSQLValueString($post_title_array[$i], "text", $TestConnection),
                       GetSQLValueString($post_title_array[$i], "text", $TestConnection),
                       GetSQLValueString($post_excerpt, "text", $TestConnection),
                       GetSQLValueString($post_status, "text", $TestConnection),
                       GetSQLValueString($comment_status, "text", $TestConnection),
                       GetSQLValueString($ping_status, "text", $TestConnection),
                       GetSQLValueString($post_password, "text", $TestConnection),
                       GetSQLValueString($post_name, "text", $TestConnection),
                       GetSQLValueString($to_ping, "text", $TestConnection),
                       GetSQLValueString($pinged, "text", $TestConnection),
                       GetSQLValueString($post_modified, "date", $TestConnection),
                       GetSQLValueString($post_modified_gmt, "date", $TestConnection),
                       GetSQLValueString($post_content_filtered, "text", $TestConnection),
                       GetSQLValueString($post_parent, "int", $TestConnection),
                       GetSQLValueString($guid, "text", $TestConnection),
                       GetSQLValueString($menu_order, "int", $TestConnection),
                       GetSQLValueString($post_type, "text", $TestConnection),
                       GetSQLValueString($post_mine_type, "text", $TestConnection),
                       GetSQLValueString($comment_count, "int", $TestConnection));

  mysqli_select_db($TestConnection,$database_TestConnection);
  $Result1 = mysqli_query($TestConnection, $insertSQL) or die(mysqli_error($TestConnection));

  $post_name = "-revision-v1"; 
  $guid = '****';
  echo "<br>Data ". ($i+1) . "succssfully inserted Into DataBase";
  //sleep(3);
 }
}

mysqli_free_result($RetrieveLatestID);
mysqli_close($TestConnection);
?>

【问题讨论】:

  • “MySQL 服务器消失”错误 真正的 mysqli 错误说什么?
  • 只有我得到“MySql Server 消失了”。

标签: php mysql web-crawler


【解决方案1】:

来自Link

MySQL server has away (error 2006)有两个主要原因和解决方法:

  • 服务器超时并关闭连接。要修复,请检查 my.cnf 配置文件中的“wait_timeout”mysql 变量是否足够大。

  • 服务器丢弃了不正确或太大的数据包。如果 mysqld 收到一个太大或不正确的数据包,它会假定客户端出现问题并关闭连接。要解决此问题,您可以在 my.cnf 文件中增加最大数据包大小限制“max_allowed_pa​​cket”,例如。设置 max_allowed_pa​​cket = 128M,然后 sudo /etc/init.d/mysql restart。

你有更完整的问题信息Here

【讨论】:

  • 如何查看 wait_timeout 和 max_allowed_pa​​cket = 128M ?我正在使用 000webhost .com(免费托管进行测试)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-20
  • 1970-01-01
  • 2010-09-14
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多