multiquery.lib.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. // get fields informations
  3. function multiquery_query($array) {
  4. $result = array();
  5. $field = 0;
  6. for ($i = 0; $i <sizeof($array); $i++) {
  7. // mysql handler
  8. $result[$i]['mysql'] = mysql_query($array[$i]);
  9. if (! $result[$i]['mysql'])
  10. die("error in query $i : ".$array[$i]);
  11. // fields
  12. $result[$i]['num_fields'] = mysql_num_fields($result[$i]['mysql']);
  13. for ($j = 0; $j < $result[$i]['num_fields']; $j++) {
  14. $name = mysql_field_name($result[$i]['mysql'], $j);
  15. $result['field'][$field]['query']=$i;
  16. $result['field'][$field]['name']=$name;
  17. $result['field'][$field]['id']=$j;
  18. $result['field_assoc'][$name][$field];
  19. $field++;
  20. }
  21. }
  22. $result['num_queries'] = sizeof($array);
  23. // rows
  24. $numberOfResult = mysql_num_rows($result[0]['mysql']);
  25. for ($i = 1; $i <$result['num_queries']; $i++)
  26. if ($numberOfResult != mysql_num_rows($result[$i]['mysql']))
  27. die("wrong number of row: $numberOfResult vs ".
  28. mysql_num_rows($result[$i]['mysql'])." on query $i");
  29. $result['num_rows'] = $numberOfResult;
  30. $result['num_fields'] = $field;
  31. return $result;
  32. }
  33. function multiquery_num_rows(&$mq_h) {
  34. return $mq_h['num_rows'];
  35. }
  36. function multiquery_num_fields(&$mq_h) {
  37. return $mq_h['num_fields'];
  38. }
  39. function multiquery_field_name(&$mq_h, $id) {
  40. return $mq_h['field'][$id]['name'];
  41. }
  42. function multiquery_fetch_row(&$mq_h) {
  43. $result = array();
  44. $pos = 0;
  45. for ($i = 0; $i < $mq_h['num_queries']; $i++) {
  46. $row = mysql_fetch_row($mq_h[$i]['mysql']);
  47. if (!$row) return false; // last line
  48. for ($j = 0; $j < sizeof($row); $j++) {
  49. $result[$pos] = $row[$j];
  50. $pos++;
  51. }
  52. }
  53. return $result;
  54. }