mysqli_query多个查询多个连接

时间:2014-02-15 17:56:15

标签: php mysql

在同一个脚本中,我正在执行3个查询,而且我总是打开一个连接:

//Second Query
 $con2= mysqli_connect($db_host,$db_username,$db_pass,$db_name); 
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
 $sql2= "INSERT INTO `documents` (doc_name,doc_type,doc_manager,doc_pointer) VALUES    ('$name', '$type', '$manager', '$pic')";
 if (!mysqli_query($con2,$sql2))
   {
   die('Error: ' . mysqli_error($con2));
   }
 mysqli_close($con2);

 //Third query 
 $con3= mysqli_connect($db_host,$db_username,$db_pass,$db_name); 
     if (mysqli_connect_errno())
         {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
         }
     $sql3="UPDATE `thor(1.0)`.`documents` SET `doc_pointer` = '$Rigth_path' WHERE `documents`.`Protocol` ='$id'";
     if (!mysqli_query($con3,$sql3))
         {
         die('Error: ' . mysqli_error($con3));
         }
     mysqli_close($con3);

(我没有发布第一个查询,因为它太长了)。 我想知道是否总是需要打开和关闭每个mysqli_query的连接,还是我可以为所有三个连接使用单个连接? 我可以用几句话来运行查询mysqli_query($con1,$sql3)

0 个答案:

没有答案