我有9個表。 我創建了一個名爲nTables次(每個表)的recoursive ajax函數 然後進入ajax我調用action.php執行搜索到每個表中。PHP mysql多個連接不起作用
問題是,在執行搜索時,當我點擊SHOW PROCESSLIST時;在mysql中,只有一個Query在運行。在我的前端頁面中,搜索會一個接一個地執行,而不是同時執行。
我能做些什麼才能讓mysql一次創建9個連接?
這裏是我的ajax:
function rAjax(thetables, i, thesearch){
i++;
$("#treethetables").hide();
$("#divsearching").show("slow", function() {});
var thetable=thetables[i];
if(i<thetables.length){
$.ajax({
type: "POST",
url: "app/action.php",
data: ({
txtBusca : thesearch,
thetable: thetable,
}),
beforeSend: function(){
$("#"+thetable).html("searching in "+thetable+"...");
},
success: function(data){
totalOkTables--;
console.warn(totalOkTables);
if(totalOkTables==0){
$("#divsearching").hide();
$("#treethetables").show("slow", function() {});
}
$("#"+thetable).append(data)
}
});
rAjax(thetables, i, thesearch)
}
}
這裏是我的連接deffinition:
class vitDb{
private $conn=NULL;
private $db=NULL;
private $selectdb=NULL;
public $dbase;
public function vitDb(){
$hostname_conn = "127.0.0.1";
$database_conn = "myBase";
$username_conn = "root";
$password_conn = "";
$this->conn = mysql_connect($hostname_conn, $username_conn, $password_conn, true) or trigger_error(mysql_error(),E_USER_ERROR);
$this->selectdb = mysql_select_db($database_conn, $this->conn);
$this->db=$database_conn;
}
public function QSet($sql){//Regresa el Juego aunque esté vacío, y NULL si error.
if($theSet=mysql_query($sql, $this->conn)){
return $theSet;
}else{
return NULL;
}
}
}
和呼叫:
$my = new vitDb();
$db=$my->dbase;
$sql="SELECT * FROM $tabla WHERE ...";
$res=$my->QSet($sql);
#Staff
希望能幫助我的感謝。
^如果您對問題進行了修改,可以對其進行編輯 - 使用上面的「編輯」鏈接。 – halfer 2015-01-20 20:49:39
**請[停止使用'mysql_ *'功能](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。**他們不再維護和[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。 **瞭解[已準備好的陳述](http://en.wikipedia.org/wiki/Prepared_statement)**,並使用[PDO](http://us1.php.net/pdo)。** – 2015-01-20 20:49:49
感謝您的評論,現在我需要解決這個古老的問題: – Nax 2015-01-20 21:01:45