CFDBQueryResultIterator

The Contact Form DB CFDBQueryResultIterator class.

Defined (1)

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

/CFDBQueryResultIterator.php  
  1. class CFDBQueryResultIterator extends CFDBAbstractQueryResultsIterator { 
  2.  
  3. /** 
  4. * @var resource|mysqli_result 
  5. */ 
  6. var $results; 
  7.  
  8. /** 
  9. * @var boolean 
  10. */ 
  11. var $useMysqli; 
  12.  
  13.  
  14. /** 
  15. * If you do not iterate over all the rows returned, be sure to call this function 
  16. * on all remaining rows to free resources. 
  17. * @return void 
  18. */ 
  19. public function freeResult() { 
  20. if ($this->results) { 
  21. if ($this->useMysqli) { 
  22. mysqli_free_result($this->results); 
  23. } else { 
  24. mysql_free_result($this->results); 
  25. $this->results = null; 
  26. /** 
  27. * @return array associative 
  28. */ 
  29. public function fetchRow() { 
  30. if ($this->useMysqli) { 
  31. return mysqli_fetch_assoc($this->results); 
  32. } else { 
  33. return mysql_fetch_assoc($this->results); 
  34.  
  35. public function hasResults() { 
  36. return !empty($this->results); 
  37.  
  38. /** 
  39. * @param $sql 
  40. * @param $queryOptions 
  41. * @return void 
  42. */ 
  43. public function queryDataSource(&$sql, $queryOptions) { 
  44. // For performance reasons, we bypass $wpdb so we can call mysql_unbuffered_query 
  45.  
  46. $this->useMysqli = $this->shouldUseMySqli(); 
  47.  
  48. $con = null; 
  49. if ($this->useMysqli) { 
  50. $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
  51. if (!$con) { 
  52. trigger_error("MySQL Connection failed: " . mysqli_error($con), E_USER_NOTICE); 
  53. return; 
  54. } else { 
  55. $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true); 
  56. if (!$con) { 
  57. trigger_error("MySQL Connection failed: " . mysql_error($con), E_USER_NOTICE); 
  58. return; 
  59.  
  60. // Target charset is in wp-config.php DB_CHARSET 
  61. if (defined('DB_CHARSET')) { 
  62. if (DB_CHARSET != '') { 
  63. global $wpdb; 
  64. if (method_exists($wpdb, 'set_charset')) { 
  65. $collate = null; 
  66. if (defined('DB_COLLATE')) { 
  67. if (DB_COLLATE != '') { 
  68. $collate = DB_COLLATE; 
  69. $wpdb->set_charset($con, DB_CHARSET, $collate); 
  70. } else { 
  71. $setCharset = 'SET NAMES \'' . DB_CHARSET . '\''; 
  72. if (defined('DB_COLLATE')) { 
  73. if (DB_COLLATE != '') { 
  74. $setCharset = $setCharset . ' COLLATE \'' . DB_COLLATE . '\''; 
  75. if ($this->useMysqli) { 
  76. mysqli_query($con, $setCharset); 
  77. } else { 
  78. mysql_query($setCharset, $con); 
  79.  
  80. if (!$this->useMysqli) { 
  81. if (!mysql_select_db(DB_NAME, $con)) { 
  82. trigger_error('MySQL DB Select failed: ' . mysql_error(), E_USER_NOTICE); 
  83. return; 
  84.  
  85. if (isset($queryOptions['unbuffered']) && $queryOptions['unbuffered'] === 'true') { 
  86. // FYI: using mysql_unbuffered_query disrupted nested shortcodes if the nested one does a query also 
  87. if ($this->useMysqli) { 
  88. $this->results = mysqli_query($con, $sql, MYSQLI_USE_RESULT); 
  89. if (!$this->results) { 
  90. trigger_error('mysqli_query failed: ' . mysql_error(), E_USER_NOTICE); 
  91. return; 
  92. } else { 
  93. $this->results = mysql_unbuffered_query($sql, $con); 
  94. if (!$this->results) { 
  95. trigger_error('mysql_unbuffered_query failed: ' . mysql_error(), E_USER_NOTICE); 
  96. return; 
  97. } else { 
  98. if ($this->useMysqli) { 
  99. $this->results = @mysqli_query($con, $sql); 
  100. if (!$this->results) { 
  101. trigger_error('mysqli_query failed. Try adding <code>unbuffered="true"</code> to your short code. <br/>' . mysql_error(), E_USER_WARNING); 
  102. return; 
  103. } else { 
  104. $this->results = @mysql_query($sql, $con); 
  105. if (!$this->results) { 
  106. trigger_error('mysql_query failed. Try adding <code>unbuffered="true"</code> to your short code. <br/>' . mysql_error(), E_USER_WARNING); 
  107. return; 
  108.  
  109. public function shouldUseMySqli() { 
  110. // This code taken from wp-db.php and adapted 
  111. $use_mysqli = false; 
  112. if ( function_exists( 'mysqli_connect' ) ) { 
  113. if ( defined( 'WP_USE_EXT_MYSQL' ) ) { 
  114. $use_mysqli = ! WP_USE_EXT_MYSQL; 
  115. } elseif ( version_compare( phpversion(), '5.5', '>=' ) || ! function_exists( 'mysql_connect' ) ) { 
  116. $use_mysqli = true; 
  117. } elseif ( false !== strpos( $GLOBALS['wp_version'], '-' ) ) { 
  118. $use_mysqli = true; 
  119. return $use_mysqli; 
  120.