你好我想存儲的MySQL結果成爲一個全球性陣列商店的MySQL結果在關聯數組
class db
{
function CustomLoad($table_name,$Fields)
{
global $_MYSQL_DATA;
$_MYSQL_DATA=array();
$qry = mysql_query("SELECT * FROM $table_name") or die(mysql_error());
while($row = mysql_fetch_assoc($qry))
{
foreach($Fields as $r=>$key)
{
$_MYSQL_DATA[$r] = $row[$r];
}
}
}
}
我打電話這樣
$dbObj = new db();
$fields = array("FIELD_1"=>"FIELD 1","FIELD_2"=>"FIELD 2","FIELD_3"=>"FIELD 3","FIELD_4"=>"FIELD 4");
$dbObj->CustomLoad("registrations",$fields);
print_r($_MYSQL_DATA);
問題是,我只得到最後的結果。像Array ([FIELD_1] => A [FIELD_2] => B [FIELD_3] => C [FIELD_4]=> D)
您應該避免使用'mysql_ *'函數,因爲它們已被棄用。改用PDO或'mysqli_ *'函數。 –