PHP/MYSQL parallel code/query execution -
am looking @ executing db queries in parallel.
my current code looks below
mysql_connect("host", "user", "pass"); $dbcheck = mysql_select_db("db"); if ($dbcheck) { /* block - 1*/ $result_1 = mysql_query($query1); if (mysql_num_rows($result_1) > 0) { while ($row_1 = mysql_fetch_assoc($result_1)) { $a=$row_1["aa1"]; $b=$row_1["aa2"]; $a[]="['".$a."',".$b."]"; } } /* block - 2*/ $result_2 = mysql_query($query2); if (mysql_num_rows($result_2) > 0) { while ($row_2 = mysql_fetch_assoc($result_2)) { $ac1=$row_2["ab1"]; $ac2=$row_2["ab2"]; $chart_array_2[]="['".$ac1."',".$ac2."]"; } } } the above runs sequentially believe. i'd execute 'block - 1' & 'block - 2' in parallel. have 20 such blocks. i'd kick them off in parallel.
i've looked on google. of them talk running db queries in parallel. i'm not able figure out way implement requirement. there way in php can kick off each of blocks in parallel please?
use looping instead
mysql_connect("host", "user", "pass"); $dbcheck = mysql_select_db("db"); if ($dbcheck) { for($i=1;$i<=20;$i++) { /* block - $i*/ $result = mysql_query($query[$i]); if (mysql_num_rows($result) > 0) { while ($row[$i] = mysql_fetch_assoc($result)) { $a[$i]=$row[$i]["aa1"]; $b[$i]=$row[$i]["aa2"]; $a[$i][]="['".$a."',".$b."]"; } } }
Comments
Post a Comment