2011-03-24 53 views
0

它可能在mysql_query中執行兩個不同的查詢並獲取這兩個查詢的記錄。執行兩個不同的查詢並獲取

+0

值得注意的是,在發現由於SQL注入造成的巨大安全風險之後,該功能在3.x-4.x天被從mysql擴展中刪除**。如果你使用古老的mysql擴展,你不應該考慮在任何情況下做這個。 – Charles 2011-03-24 07:00:02

回答

1

的mysql_query不支持此

u可以使用

mysqli::multi_query

<?php 
$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); 

/* check connection */ 
if (mysqli_connect_errno()) { 
    printf("Connect failed: %s\n", mysqli_connect_error()); 
    exit(); 
} 

$query = "SELECT CURRENT_USER();"; 
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5"; 

/* execute multi query */ 
if ($mysqli->multi_query($query)) { 
    do { 
     /* store first result set */ 
     if ($result = $mysqli->store_result()) { 
      while ($row = $result->fetch_row()) { 
       printf("%s\n", $row[0]); 
      } 
      $result->free(); 
     } 
     /* print divider */ 
     if ($mysqli->more_results()) { 
      printf("-----------------\n"); 
     } 
    } while ($mysqli->next_result()); 
} 

/* close connection */ 
$mysqli->close(); 
?> 
0

65536用於運行在MySQL多個查詢,但我不知道這會幫助你或沒有。但我用這個來調用php程序。

$con = mysql_connect('localhost','root','',false,65536); //65536 is used to fire multiple query. 
相關問題