CFDBWpdbUnbufferedResultIterator

The Contact Form DB CFDBWpdbUnbufferedResultIterator class.

Defined (1)

The class is defined in the following location(s).

/CFDBWpdbUnbufferedResultIterator.php  
  1. class CFDBWpdbUnbufferedResultIterator extends CFDBAbstractQueryResultsIterator { 
  2.  
  3. /** 
  4. * @var resource|mysqli_result 
  5. */ 
  6. var $mysqlResults; 
  7.  
  8. /** 
  9. * @var boolean 
  10. */ 
  11. var $useMysqli; 
  12.  
  13. /** 
  14. * @var bool 
  15. */ 
  16. var $debug = false; 
  17.  
  18. /** 
  19. * Doesn't work right if we use the global $wpdb,  
  20. * so this class constructs its own instance 
  21. * @var wpdb 
  22. */ 
  23. var $wpdb; 
  24.  
  25.  
  26. /** 
  27. * Execute the query 
  28. * @param $sql string query 
  29. * @param $queryOptions array associative 
  30. * @return void 
  31. */ 
  32. public function queryDataSource(&$sql, $queryOptions) { 
  33. $this->wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 
  34.  
  35. $this->debug = WP_DEBUG || 
  36. (is_array($queryOptions) && 
  37. isset($queryOptions['debug']) && 
  38. $queryOptions['debug'] == true); 
  39.  
  40. $this->useMysqli = $this->shouldUseMySqli(); 
  41.  
  42. if ($this->useMysqli) { 
  43. if ($this->debug) { 
  44. $this->mysqlResults = mysqli_query($this->wpdb->dbh, $sql, MYSQLI_USE_RESULT); 
  45. } else { 
  46. $this->mysqlResults = @mysqli_query($this->wpdb->dbh, $sql, MYSQLI_USE_RESULT); 
  47. } else { 
  48. if ($this->debug) { 
  49. $this->mysqlResults = mysql_unbuffered_query($sql, $this->wpdb->dbh); 
  50. } else { 
  51. $this->mysqlResults = @mysql_unbuffered_query($sql, $this->wpdb->dbh); 
  52.  
  53. /** 
  54. * Get the next row from query results 
  55. * @return array|null|false (array is associative) 
  56. */ 
  57. public function fetchRow() { 
  58. $row = null; 
  59. if ($this->useMysqli) { 
  60. if ($this->debug) { 
  61. // returns array|null 
  62. $row = mysqli_fetch_assoc($this->mysqlResults); 
  63. } else { 
  64. // returns array|null 
  65. $row = @mysqli_fetch_assoc($this->mysqlResults); 
  66. } else { 
  67. if ($this->debug) { 
  68. // returns array|false 
  69. $row = mysql_fetch_assoc($this->mysqlResults); 
  70. } else { 
  71. // returns array|false 
  72. $row = @mysql_fetch_assoc($this->mysqlResults); 
  73. return $row; 
  74.  
  75. /** 
  76. * If you do not iterate over all the rows returned, be sure to call this function 
  77. * on all remaining rows to free resources. 
  78. * @return void 
  79. */ 
  80. public function freeResult() { 
  81. if ($this->mysqlResults) { 
  82. if ($this->useMysqli) { 
  83. if ($this->debug) { 
  84. mysqli_free_result($this->mysqlResults); 
  85. } else { 
  86. @mysqli_free_result($this->mysqlResults); 
  87. } else { 
  88. if ($this->debug) { 
  89. mysql_free_result($this->mysqlResults); 
  90. } else { 
  91. @mysql_free_result($this->mysqlResults); 
  92. $this->mysqlResults = null; 
  93. $this->wpdb->flush(); 
  94.  
  95.  
  96. public function shouldUseMySqli() { 
  97. // This code taken from wp-db.php and adapted 
  98. // Had to add this here because $wpdb->use_mysqli is private/inaccessible 
  99. $use_mysqli = false; 
  100. if (function_exists('mysqli_connect')) { 
  101. if (defined('WP_USE_EXT_MYSQL')) { 
  102. $use_mysqli = !WP_USE_EXT_MYSQL; 
  103. } elseif (version_compare(phpversion(), '5.5', '>=') || !function_exists('mysql_connect')) { 
  104. $use_mysqli = true; 
  105. } elseif (false !== strpos($GLOBALS['wp_version'], '-')) { 
  106. $use_mysqli = true; 
  107. return $use_mysqli; 
  108.