BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sphinxqlresult.class.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. class SphinxqlResult
  3. {
  4. private $Result;
  5. private $Meta;
  6. public $Errno;
  7. public $Error;
  8. /**
  9. * Create Sphinxql result object
  10. *
  11. * @param mysqli_result $Result query results
  12. * @param array $Meta meta data for the query
  13. * @param int $Errno error code returned by the query upon failure
  14. * @param string $Error error message returned by the query upon failure
  15. */
  16. public function __construct($Result, $Meta, $Errno, $Error)
  17. {
  18. $this->Result = $Result;
  19. $this->Meta = $Meta;
  20. $this->Errno = $Errno;
  21. $this->Error = $Error;
  22. }
  23. /**
  24. * Redirect to the Mysqli result object if a nonexistent method is called
  25. *
  26. * @param string $Name method name
  27. * @param array $Arguments arguments used in the function call
  28. * @return whatever the parent function returns
  29. */
  30. public function __call($Name, $Arguments)
  31. {
  32. return call_user_func_array(array($this->Result, $Name), $Arguments);
  33. }
  34. /**
  35. * Did the query find anything?
  36. *
  37. * @return bool results were found
  38. */
  39. public function has_results()
  40. {
  41. return $this->get_meta('total') > 0;
  42. }
  43. /**
  44. * Collect and return the specified key of all results as a list
  45. *
  46. * @param string $Key key containing the desired data
  47. * @return array with the $Key value of all results
  48. */
  49. public function collect($Key)
  50. {
  51. $Return = [];
  52. while ($Row = $this->fetch_array()) {
  53. $Return[] = $Row[$Key];
  54. }
  55. $this->data_seek(0);
  56. return $Return;
  57. }
  58. /**
  59. * Collect and return all available data for the matches optionally indexed by a specified key
  60. *
  61. * @param string $Key key to use as indexing value
  62. * @param string $ResultType method to use when fetching data from the mysqli_result object. Default is MYSQLI_ASSOC
  63. * @return array with all available data for the matches
  64. */
  65. public function to_array($Key, $ResultType = MYSQLI_ASSOC)
  66. {
  67. $Return = [];
  68. while ($Row = $this->fetch_array($ResultType)) {
  69. if ($Key !== false) {
  70. $Return[$Row[$Key]] = $Row;
  71. } else {
  72. $Return[] = $Row;
  73. }
  74. }
  75. $this->data_seek(0);
  76. return $Return;
  77. }
  78. /**
  79. * Collect pairs of keys for all matches
  80. *
  81. * @param string $Key1 key to use as indexing value
  82. * @param string $Key2 key to use as value
  83. * @return array with $Key1 => $Key2 pairs for matches
  84. */
  85. public function to_pair($Key1, $Key2)
  86. {
  87. $Return = [];
  88. while ($Row = $this->fetch_array()) {
  89. $Return[$Row[$Key1]] = $Row[$Key2];
  90. }
  91. $this->data_seek(0);
  92. return $Return;
  93. }
  94. /**
  95. * Return specified portions of the current Sphinxql result object's meta data
  96. *
  97. * @param mixed $Keys scalar or array with keys to return. Default is false, which returns all meta data
  98. * @return array with meta data
  99. */
  100. public function get_meta($Keys = false)
  101. {
  102. if ($Keys !== false) {
  103. if (is_array($Keys)) {
  104. $Return = [];
  105. foreach ($Keys as $Key) {
  106. if (!isset($this->Meta[$Key])) {
  107. continue;
  108. }
  109. $Return[$Key] = $this->Meta[$Key];
  110. }
  111. return $Return;
  112. } else {
  113. return isset($this->Meta[$Keys]) ? $this->Meta[$Keys] : false;
  114. }
  115. } else {
  116. return $this->Meta;
  117. }
  118. }
  119. /**
  120. * Return specified portions of the current Mysqli result object's information
  121. *
  122. * @param mixed $Keys scalar or array with keys to return. Default is false, which returns all available information
  123. * @return array with result information
  124. */
  125. public function get_result_info($Keys = false)
  126. {
  127. if ($Keys !== false) {
  128. if (is_array($Keys)) {
  129. $Return = [];
  130. foreach ($Keys as $Key) {
  131. if (!isset($this->Result->$Key)) {
  132. continue;
  133. }
  134. $Return[$Key] = $this->Result->$Key;
  135. }
  136. return $Return;
  137. } else {
  138. return isset($this->Result->$Keys) ? $this->Result->$Keys : false;
  139. }
  140. } else {
  141. return $this->Result;
  142. }
  143. }
  144. }