【问题标题】:Getting Mysql_Close Error [closed]获取 Mysql_Close 错误 [关闭]
【发布时间】:2011-08-09 19:07:52
【问题描述】:

我收到以下代码的 mysql_close() 错误,尽管我认为语法是正确的。它打开正常,变量是正确的。有什么建议么?代码在这里 (http://obsidianpunch.com/Summer) 错误是警告:mysql_close(): 5 is not a valid MySQL-Link resource in /home/content/53/7382753/html/Summer/wootsummer.php on第 97 行

第 97 行是

mysql_close($con);

这里是 wootsummer.php

<html>
<body>

<?php

error_reporting(E_ALL);
set_time_limit (0);

$urls=explode("\n", $_POST['url']);
//$proxies=explode("\n", $_POST['proxy']);

$target=$_POST['target'];

$allurls=count($urls);
//$allproxies=count($proxies);

//use the new tool box
require "ToolBoxA4.php";


for ( $counter = 0; $counter < $allurls; $counter++) {
//for ( $count = 0; $count <= $allproxies; $count++) {


 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$urls[$counter]);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
 curl_setopt ($ch, CURLOPT_HEADER, 1); 
 curl_exec ($ch); 
 $curl_scraped_page=curl_exec($ch); 


//call the new function parseA1
$arrOut = parseA1 ($curl_scraped_page);


$curl_scraped_page=strtolower($curl_scraped_page);
$haystack=$curl_scraped_page;
if (strlen(strstr($haystack,$target))>0) {



$FileName = abs(rand(0,100000));
$FileHandle = fopen($FileName, 'w') or die("can't open file");
fwrite($FileHandle, $curl_scraped_page);


$hostname="*******";
$username="hatrick";
$password="*******";
$dbname="hatrick";
$usertable="happyturtle";

$con=mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname ,$con);
if (!$con)
   {
   die(mysql_error());
   }
 mysql_close($con);

$right = explode(",", $arrOut[0]);
$top = explode(",", $arrOut[1]);

for ( $countforme = 0; $countforme < 6; $countforme++) {
//$topnow=$top[$countforme];
//echo '$topnow';

$query = "INSERT INTO happyturtle (time, ad1) VALUES ('00987','www.hats.com')";
//mysql_query($query) or die('Error, insert query failed');
if (!$query)
   {
   die(mysql_error());
   }
 //mysql_close($con);


}

for ( $countforme = 0; $countforme <= 15; $countforme++) {

//$rightnow = $right[$countforme];


$query = "INSERT INTO happyturtle (time, ad1) VALUES ('00987','www.hats.com')";
//mysql_query($query) or die('Error, insert query failed');
if (!$query)
   {
   die(mysql_error());
   }
 //mysql_close($con);

}

mysql_close($con);


echo '$FileNameSQL';


fclose($FileHandle);
}
curl_close($ch);

}



?>

</body>
</html>

谢谢!

【问题讨论】:

    标签: php mysql curl database-connection mysql-error-1064


    【解决方案1】:

    快速浏览显示多个副本:

     mysql_close($con);
    

    所以在那条线上,它已经关闭了。

    打开后立即关闭:

    $con=mysql_connect(.............
    mysql_select_db($dbname ,$con);
    if (!$con)
    {
      die(mysql_error());
    }
    mysql_close($con);
    

    稍后再尝试关闭它。

    【讨论】:

      【解决方案2】:

      你打开连接,然后立即关闭它:

      if (!$con)
      {
      die(mysql_error());
      }
      mysql_close($con);
      

      稍后,您尝试执行查询,但您的连接已关闭。如果您打算将上面的mysql_close()die() 一起放在if 块内,则不需要在那里。它应该被完全删除。

      【讨论】:

        【解决方案3】:

        删除除最后一个之外的所有mysql_close($con);

        【讨论】:

          猜你喜欢
          • 2015-11-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-08-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多