Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 找不到数据库!!mysql错误_Php_Mysql_Sql - Fatal编程技术网

Php 找不到数据库!!mysql错误

Php 找不到数据库!!mysql错误,php,mysql,sql,Php,Mysql,Sql,我每次都会收到这个…我做错了什么 未选择任何数据库 我正在从外部文件调用该函数…如下 //require_once("../StoredProcedure/connect.php"); $conn=mysql_connect("localhost","root","") or die(mysql_error); mysql_select_db("politicalforum",$conn); function updateThread($threadID, $conten

我每次都会收到这个…我做错了什么

未选择任何数据库

我正在从外部文件调用该函数…如下

     //require_once("../StoredProcedure/connect.php");
  $conn=mysql_connect("localhost","root","") or die(mysql_error);
  mysql_select_db("politicalforum",$conn); 

 function updateThread($threadID, $content) 
 {
     mysql_query("UPDATE threads
                  SET content='$content'  
                  WHERE thread_id=$threadID") ;
    // $res = mysql_query($sql) or trigger_error(mysql_error().$sql);
     mysql_close();
 }

您的连接可能超出范围,导致mysql_查询针对上下文的数据库对象运行,该对象在
updateThread
激发时不存在

在这种情况下,需要将连接传递到
mysql\u query
函数中
updateThread
。在架构上,有两种方法可以实现这一点:

1) 打开并关闭
updateThread
函数中的连接:

if(isset($_GET['threadID']) && isset($_POST["reply"]) && isset($_POST['textareas']))
   {

        updateThread($_GET['threadID'], $_POST['textareas']); 

       $postValid=TRUE;
   }
2) 如果要在其他函数中使用相同的连接,请将该连接作为变量传递给updateThread。脚本完成后,PHP将自动关闭并处理您的MySQL连接:

function updateThread($threadID, $content) 
{
   $conn=mysql_connect("localhost","root","") or die(mysql_error);
   mysql_select_db("politicalforum",$conn); 
   mysql_query("UPDATE threads
                SET content='$content'  
                WHERE thread_id=$threadID", $conn) ;
   mysql_close($conn);
   $conn = null;
}

您的连接可能超出范围,导致mysql_查询针对上下文的数据库对象运行,该对象在
updateThread
激发时不存在

在这种情况下,需要将连接传递到
mysql\u query
函数中
updateThread
。在架构上,有两种方法可以实现这一点:

1) 打开并关闭
updateThread
函数中的连接:

if(isset($_GET['threadID']) && isset($_POST["reply"]) && isset($_POST['textareas']))
   {

        updateThread($_GET['threadID'], $_POST['textareas']); 

       $postValid=TRUE;
   }
2) 如果要在其他函数中使用相同的连接,请将该连接作为变量传递给updateThread。脚本完成后,PHP将自动关闭并处理您的MySQL连接:

function updateThread($threadID, $content) 
{
   $conn=mysql_connect("localhost","root","") or die(mysql_error);
   mysql_select_db("politicalforum",$conn); 
   mysql_query("UPDATE threads
                SET content='$content'  
                WHERE thread_id=$threadID", $conn) ;
   mysql_close($conn);
   $conn = null;
}

数据库选择必须在函数内部进行。你可能想考虑做一个类。你检查了<代码> MySqLyStReTypDb<代码>的结果吗?那是什么?@Truth:那是为什么?是的,很可能你的select_db失败了,函数调用了两次?第二次调用不起作用,因为第一次调用终止了与
mysql\u close()
的连接。数据库选择必须在函数内部进行。你可能想考虑做一个类。你检查了<代码> MySqLyStReTypDb<代码>的结果吗?那是什么?@Truth:那是为什么?是的,很可能你的select_db失败了,函数调用了两次?第二次调用不起作用,因为第一次调用终止了与第二个解决方案的
mysql\u close()
+1的连接。我不认为一直打开和关闭连接是聪明的,所以我永远不会这样做(1)。在这种情况下,最好创建一次连接,然后将其作为参数+1传递给第二个解决方案。我不认为一直打开和关闭连接是聪明的,所以我从来没有这样做过(1)。在这种情况下,创建一次连接,然后将其作为参数传递似乎更好