Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../public_h.../clone/wp-inclu...
File: class-wpdb.php
// Extract placeholders from the query.
[1500] Fix | Delete
$split_query = preg_split( "/(^|[^%]|(?:%%)+)(%(?:$allowed_format)?[sdfFi])/", $query, -1, PREG_SPLIT_DELIM_CAPTURE );
[1501] Fix | Delete
[1502] Fix | Delete
$split_query_count = count( $split_query );
[1503] Fix | Delete
[1504] Fix | Delete
/*
[1505] Fix | Delete
* Split always returns with 1 value before the first placeholder (even with $query = "%s"),
[1506] Fix | Delete
* then 3 additional values per placeholder.
[1507] Fix | Delete
*/
[1508] Fix | Delete
$placeholder_count = ( ( $split_query_count - 1 ) / 3 );
[1509] Fix | Delete
[1510] Fix | Delete
// If args were passed as an array, as in vsprintf(), move them up.
[1511] Fix | Delete
$passed_as_array = ( isset( $args[0] ) && is_array( $args[0] ) && 1 === count( $args ) );
[1512] Fix | Delete
if ( $passed_as_array ) {
[1513] Fix | Delete
$args = $args[0];
[1514] Fix | Delete
}
[1515] Fix | Delete
[1516] Fix | Delete
$new_query = '';
[1517] Fix | Delete
$key = 2; // Keys 0 and 1 in $split_query contain values before the first placeholder.
[1518] Fix | Delete
$arg_id = 0;
[1519] Fix | Delete
$arg_identifiers = array();
[1520] Fix | Delete
$arg_strings = array();
[1521] Fix | Delete
[1522] Fix | Delete
while ( $key < $split_query_count ) {
[1523] Fix | Delete
$placeholder = $split_query[ $key ];
[1524] Fix | Delete
[1525] Fix | Delete
$format = substr( $placeholder, 1, -1 );
[1526] Fix | Delete
$type = substr( $placeholder, -1 );
[1527] Fix | Delete
[1528] Fix | Delete
if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters
[1529] Fix | Delete
/*
[1530] Fix | Delete
* Note: str_ends_with() is not used here, as this file can be included
[1531] Fix | Delete
* directly outside of WordPress core, e.g. by HyperDB, in which case
[1532] Fix | Delete
* the polyfills from wp-includes/compat.php are not loaded.
[1533] Fix | Delete
*/
[1534] Fix | Delete
&& '%' === substr( $split_query[ $key - 1 ], -1, 1 )
[1535] Fix | Delete
) {
[1536] Fix | Delete
[1537] Fix | Delete
/*
[1538] Fix | Delete
* Before WP 6.2 the "force floats to be locale-unaware" RegEx didn't
[1539] Fix | Delete
* convert "%%%f" to "%%%F" (note the uppercase F).
[1540] Fix | Delete
* This was because it didn't check to see if the leading "%" was escaped.
[1541] Fix | Delete
* And because the "Escape any unescaped percents" RegEx used "[sdF]" in its
[1542] Fix | Delete
* negative lookahead assertion, when there was an odd number of "%", it added
[1543] Fix | Delete
* an extra "%", to give the fully escaped "%%%%f" (not a placeholder).
[1544] Fix | Delete
*/
[1545] Fix | Delete
[1546] Fix | Delete
$s = $split_query[ $key - 2 ] . $split_query[ $key - 1 ];
[1547] Fix | Delete
$k = 1;
[1548] Fix | Delete
$l = strlen( $s );
[1549] Fix | Delete
while ( $k <= $l && '%' === $s[ $l - $k ] ) {
[1550] Fix | Delete
++$k;
[1551] Fix | Delete
}
[1552] Fix | Delete
[1553] Fix | Delete
$placeholder = '%' . ( $k % 2 ? '%' : '' ) . $format . $type;
[1554] Fix | Delete
[1555] Fix | Delete
--$placeholder_count;
[1556] Fix | Delete
[1557] Fix | Delete
} else {
[1558] Fix | Delete
[1559] Fix | Delete
// Force floats to be locale-unaware.
[1560] Fix | Delete
if ( 'f' === $type ) {
[1561] Fix | Delete
$type = 'F';
[1562] Fix | Delete
$placeholder = '%' . $format . $type;
[1563] Fix | Delete
}
[1564] Fix | Delete
[1565] Fix | Delete
if ( 'i' === $type ) {
[1566] Fix | Delete
$placeholder = '`%' . $format . 's`';
[1567] Fix | Delete
// Using a simple strpos() due to previous checking (e.g. $allowed_format).
[1568] Fix | Delete
$argnum_pos = strpos( $format, '$' );
[1569] Fix | Delete
[1570] Fix | Delete
if ( false !== $argnum_pos ) {
[1571] Fix | Delete
// sprintf() argnum starts at 1, $arg_id from 0.
[1572] Fix | Delete
$arg_identifiers[] = ( ( (int) substr( $format, 0, $argnum_pos ) ) - 1 );
[1573] Fix | Delete
} else {
[1574] Fix | Delete
$arg_identifiers[] = $arg_id;
[1575] Fix | Delete
}
[1576] Fix | Delete
} elseif ( 'd' !== $type && 'F' !== $type ) {
[1577] Fix | Delete
/*
[1578] Fix | Delete
* i.e. ( 's' === $type ), where 'd' and 'F' keeps $placeholder unchanged,
[1579] Fix | Delete
* and we ensure string escaping is used as a safe default (e.g. even if 'x').
[1580] Fix | Delete
*/
[1581] Fix | Delete
$argnum_pos = strpos( $format, '$' );
[1582] Fix | Delete
[1583] Fix | Delete
if ( false !== $argnum_pos ) {
[1584] Fix | Delete
$arg_strings[] = ( ( (int) substr( $format, 0, $argnum_pos ) ) - 1 );
[1585] Fix | Delete
} else {
[1586] Fix | Delete
$arg_strings[] = $arg_id;
[1587] Fix | Delete
}
[1588] Fix | Delete
[1589] Fix | Delete
/*
[1590] Fix | Delete
* Unquoted strings for backward compatibility (dangerous).
[1591] Fix | Delete
* First, "numbered or formatted string placeholders (eg, %1$s, %5s)".
[1592] Fix | Delete
* Second, if "%s" has a "%" before it, even if it's unrelated (e.g. "LIKE '%%%s%%'").
[1593] Fix | Delete
*/
[1594] Fix | Delete
if ( true !== $this->allow_unsafe_unquoted_parameters
[1595] Fix | Delete
/*
[1596] Fix | Delete
* Note: str_ends_with() is not used here, as this file can be included
[1597] Fix | Delete
* directly outside of WordPress core, e.g. by HyperDB, in which case
[1598] Fix | Delete
* the polyfills from wp-includes/compat.php are not loaded.
[1599] Fix | Delete
*/
[1600] Fix | Delete
|| ( '' === $format && '%' !== substr( $split_query[ $key - 1 ], -1, 1 ) )
[1601] Fix | Delete
) {
[1602] Fix | Delete
$placeholder = "'%" . $format . "s'";
[1603] Fix | Delete
}
[1604] Fix | Delete
}
[1605] Fix | Delete
}
[1606] Fix | Delete
[1607] Fix | Delete
// Glue (-2), any leading characters (-1), then the new $placeholder.
[1608] Fix | Delete
$new_query .= $split_query[ $key - 2 ] . $split_query[ $key - 1 ] . $placeholder;
[1609] Fix | Delete
[1610] Fix | Delete
$key += 3;
[1611] Fix | Delete
++$arg_id;
[1612] Fix | Delete
}
[1613] Fix | Delete
[1614] Fix | Delete
// Replace $query; and add remaining $query characters, or index 0 if there were no placeholders.
[1615] Fix | Delete
$query = $new_query . $split_query[ $key - 2 ];
[1616] Fix | Delete
[1617] Fix | Delete
$dual_use = array_intersect( $arg_identifiers, $arg_strings );
[1618] Fix | Delete
[1619] Fix | Delete
if ( count( $dual_use ) > 0 ) {
[1620] Fix | Delete
wp_load_translations_early();
[1621] Fix | Delete
[1622] Fix | Delete
$used_placeholders = array();
[1623] Fix | Delete
[1624] Fix | Delete
$key = 2;
[1625] Fix | Delete
$arg_id = 0;
[1626] Fix | Delete
// Parse again (only used when there is an error).
[1627] Fix | Delete
while ( $key < $split_query_count ) {
[1628] Fix | Delete
$placeholder = $split_query[ $key ];
[1629] Fix | Delete
[1630] Fix | Delete
$format = substr( $placeholder, 1, -1 );
[1631] Fix | Delete
[1632] Fix | Delete
$argnum_pos = strpos( $format, '$' );
[1633] Fix | Delete
[1634] Fix | Delete
if ( false !== $argnum_pos ) {
[1635] Fix | Delete
$arg_pos = ( ( (int) substr( $format, 0, $argnum_pos ) ) - 1 );
[1636] Fix | Delete
} else {
[1637] Fix | Delete
$arg_pos = $arg_id;
[1638] Fix | Delete
}
[1639] Fix | Delete
[1640] Fix | Delete
$used_placeholders[ $arg_pos ][] = $placeholder;
[1641] Fix | Delete
[1642] Fix | Delete
$key += 3;
[1643] Fix | Delete
++$arg_id;
[1644] Fix | Delete
}
[1645] Fix | Delete
[1646] Fix | Delete
$conflicts = array();
[1647] Fix | Delete
foreach ( $dual_use as $arg_pos ) {
[1648] Fix | Delete
$conflicts[] = implode( ' and ', $used_placeholders[ $arg_pos ] );
[1649] Fix | Delete
}
[1650] Fix | Delete
[1651] Fix | Delete
_doing_it_wrong(
[1652] Fix | Delete
'wpdb::prepare',
[1653] Fix | Delete
sprintf(
[1654] Fix | Delete
/* translators: %s: A list of placeholders found to be a problem. */
[1655] Fix | Delete
__( 'Arguments cannot be prepared as both an Identifier and Value. Found the following conflicts: %s' ),
[1656] Fix | Delete
implode( ', ', $conflicts )
[1657] Fix | Delete
),
[1658] Fix | Delete
'6.2.0'
[1659] Fix | Delete
);
[1660] Fix | Delete
[1661] Fix | Delete
return;
[1662] Fix | Delete
}
[1663] Fix | Delete
[1664] Fix | Delete
$args_count = count( $args );
[1665] Fix | Delete
[1666] Fix | Delete
if ( $args_count !== $placeholder_count ) {
[1667] Fix | Delete
if ( 1 === $placeholder_count && $passed_as_array ) {
[1668] Fix | Delete
/*
[1669] Fix | Delete
* If the passed query only expected one argument,
[1670] Fix | Delete
* but the wrong number of arguments was sent as an array, bail.
[1671] Fix | Delete
*/
[1672] Fix | Delete
wp_load_translations_early();
[1673] Fix | Delete
_doing_it_wrong(
[1674] Fix | Delete
'wpdb::prepare',
[1675] Fix | Delete
__( 'The query only expected one placeholder, but an array of multiple placeholders was sent.' ),
[1676] Fix | Delete
'4.9.0'
[1677] Fix | Delete
);
[1678] Fix | Delete
[1679] Fix | Delete
return;
[1680] Fix | Delete
} else {
[1681] Fix | Delete
/*
[1682] Fix | Delete
* If we don't have the right number of placeholders,
[1683] Fix | Delete
* but they were passed as individual arguments,
[1684] Fix | Delete
* or we were expecting multiple arguments in an array, throw a warning.
[1685] Fix | Delete
*/
[1686] Fix | Delete
wp_load_translations_early();
[1687] Fix | Delete
_doing_it_wrong(
[1688] Fix | Delete
'wpdb::prepare',
[1689] Fix | Delete
sprintf(
[1690] Fix | Delete
/* translators: 1: Number of placeholders, 2: Number of arguments passed. */
[1691] Fix | Delete
__( 'The query does not contain the correct number of placeholders (%1$d) for the number of arguments passed (%2$d).' ),
[1692] Fix | Delete
$placeholder_count,
[1693] Fix | Delete
$args_count
[1694] Fix | Delete
),
[1695] Fix | Delete
'4.8.3'
[1696] Fix | Delete
);
[1697] Fix | Delete
[1698] Fix | Delete
/*
[1699] Fix | Delete
* If we don't have enough arguments to match the placeholders,
[1700] Fix | Delete
* return an empty string to avoid a fatal error on PHP 8.
[1701] Fix | Delete
*/
[1702] Fix | Delete
if ( $args_count < $placeholder_count ) {
[1703] Fix | Delete
$max_numbered_placeholder = 0;
[1704] Fix | Delete
[1705] Fix | Delete
for ( $i = 2, $l = $split_query_count; $i < $l; $i += 3 ) {
[1706] Fix | Delete
// Assume a leading number is for a numbered placeholder, e.g. '%3$s'.
[1707] Fix | Delete
$argnum = (int) substr( $split_query[ $i ], 1 );
[1708] Fix | Delete
[1709] Fix | Delete
if ( $max_numbered_placeholder < $argnum ) {
[1710] Fix | Delete
$max_numbered_placeholder = $argnum;
[1711] Fix | Delete
}
[1712] Fix | Delete
}
[1713] Fix | Delete
[1714] Fix | Delete
if ( ! $max_numbered_placeholder || $args_count < $max_numbered_placeholder ) {
[1715] Fix | Delete
return '';
[1716] Fix | Delete
}
[1717] Fix | Delete
}
[1718] Fix | Delete
}
[1719] Fix | Delete
}
[1720] Fix | Delete
[1721] Fix | Delete
$args_escaped = array();
[1722] Fix | Delete
[1723] Fix | Delete
foreach ( $args as $i => $value ) {
[1724] Fix | Delete
if ( in_array( $i, $arg_identifiers, true ) ) {
[1725] Fix | Delete
$args_escaped[] = $this->_escape_identifier_value( $value );
[1726] Fix | Delete
} elseif ( is_int( $value ) || is_float( $value ) ) {
[1727] Fix | Delete
$args_escaped[] = $value;
[1728] Fix | Delete
} else {
[1729] Fix | Delete
if ( ! is_scalar( $value ) && ! is_null( $value ) ) {
[1730] Fix | Delete
wp_load_translations_early();
[1731] Fix | Delete
_doing_it_wrong(
[1732] Fix | Delete
'wpdb::prepare',
[1733] Fix | Delete
sprintf(
[1734] Fix | Delete
/* translators: %s: Value type. */
[1735] Fix | Delete
__( 'Unsupported value type (%s).' ),
[1736] Fix | Delete
gettype( $value )
[1737] Fix | Delete
),
[1738] Fix | Delete
'4.8.2'
[1739] Fix | Delete
);
[1740] Fix | Delete
[1741] Fix | Delete
// Preserving old behavior, where values are escaped as strings.
[1742] Fix | Delete
$value = '';
[1743] Fix | Delete
}
[1744] Fix | Delete
[1745] Fix | Delete
$args_escaped[] = $this->_real_escape( $value );
[1746] Fix | Delete
}
[1747] Fix | Delete
}
[1748] Fix | Delete
[1749] Fix | Delete
$query = vsprintf( $query, $args_escaped );
[1750] Fix | Delete
[1751] Fix | Delete
return $this->add_placeholder_escape( $query );
[1752] Fix | Delete
}
[1753] Fix | Delete
[1754] Fix | Delete
/**
[1755] Fix | Delete
* First half of escaping for `LIKE` special characters `%` and `_` before preparing for SQL.
[1756] Fix | Delete
*
[1757] Fix | Delete
* Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security.
[1758] Fix | Delete
*
[1759] Fix | Delete
* Example Prepared Statement:
[1760] Fix | Delete
*
[1761] Fix | Delete
* $wild = '%';
[1762] Fix | Delete
* $find = 'only 43% of planets';
[1763] Fix | Delete
* $like = $wild . $wpdb->esc_like( $find ) . $wild;
[1764] Fix | Delete
* $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE %s", $like );
[1765] Fix | Delete
*
[1766] Fix | Delete
* Example Escape Chain:
[1767] Fix | Delete
*
[1768] Fix | Delete
* $sql = esc_sql( $wpdb->esc_like( $input ) );
[1769] Fix | Delete
*
[1770] Fix | Delete
* @since 4.0.0
[1771] Fix | Delete
*
[1772] Fix | Delete
* @param string $text The raw text to be escaped. The input typed by the user
[1773] Fix | Delete
* should have no extra or deleted slashes.
[1774] Fix | Delete
* @return string Text in the form of a LIKE phrase. The output is not SQL safe.
[1775] Fix | Delete
* Call wpdb::prepare() or wpdb::_real_escape() next.
[1776] Fix | Delete
*/
[1777] Fix | Delete
public function esc_like( $text ) {
[1778] Fix | Delete
return addcslashes( $text, '_%\\' );
[1779] Fix | Delete
}
[1780] Fix | Delete
[1781] Fix | Delete
/**
[1782] Fix | Delete
* Prints SQL/DB error.
[1783] Fix | Delete
*
[1784] Fix | Delete
* @since 0.71
[1785] Fix | Delete
*
[1786] Fix | Delete
* @global array $EZSQL_ERROR Stores error information of query and error string.
[1787] Fix | Delete
*
[1788] Fix | Delete
* @param string $str The error to display.
[1789] Fix | Delete
* @return void|false Void if the showing of errors is enabled, false if disabled.
[1790] Fix | Delete
*/
[1791] Fix | Delete
public function print_error( $str = '' ) {
[1792] Fix | Delete
global $EZSQL_ERROR;
[1793] Fix | Delete
[1794] Fix | Delete
if ( ! $str ) {
[1795] Fix | Delete
$str = mysqli_error( $this->dbh );
[1796] Fix | Delete
}
[1797] Fix | Delete
[1798] Fix | Delete
$EZSQL_ERROR[] = array(
[1799] Fix | Delete
'query' => $this->last_query,
[1800] Fix | Delete
'error_str' => $str,
[1801] Fix | Delete
);
[1802] Fix | Delete
[1803] Fix | Delete
if ( $this->suppress_errors ) {
[1804] Fix | Delete
return false;
[1805] Fix | Delete
}
[1806] Fix | Delete
[1807] Fix | Delete
$caller = $this->get_caller();
[1808] Fix | Delete
if ( $caller ) {
[1809] Fix | Delete
// Not translated, as this will only appear in the error log.
[1810] Fix | Delete
$error_str = sprintf( 'WordPress database error %1$s for query %2$s made by %3$s', $str, $this->last_query, $caller );
[1811] Fix | Delete
} else {
[1812] Fix | Delete
$error_str = sprintf( 'WordPress database error %1$s for query %2$s', $str, $this->last_query );
[1813] Fix | Delete
}
[1814] Fix | Delete
[1815] Fix | Delete
error_log( $error_str );
[1816] Fix | Delete
[1817] Fix | Delete
// Are we showing errors?
[1818] Fix | Delete
if ( ! $this->show_errors ) {
[1819] Fix | Delete
return false;
[1820] Fix | Delete
}
[1821] Fix | Delete
[1822] Fix | Delete
wp_load_translations_early();
[1823] Fix | Delete
[1824] Fix | Delete
// If there is an error then take note of it.
[1825] Fix | Delete
if ( is_multisite() ) {
[1826] Fix | Delete
$msg = sprintf(
[1827] Fix | Delete
"%s [%s]\n%s\n",
[1828] Fix | Delete
__( 'WordPress database error:' ),
[1829] Fix | Delete
$str,
[1830] Fix | Delete
$this->last_query
[1831] Fix | Delete
);
[1832] Fix | Delete
[1833] Fix | Delete
if ( defined( 'ERRORLOGFILE' ) ) {
[1834] Fix | Delete
error_log( $msg, 3, ERRORLOGFILE );
[1835] Fix | Delete
}
[1836] Fix | Delete
if ( defined( 'DIEONDBERROR' ) ) {
[1837] Fix | Delete
wp_die( $msg );
[1838] Fix | Delete
}
[1839] Fix | Delete
} else {
[1840] Fix | Delete
$str = htmlspecialchars( $str, ENT_QUOTES );
[1841] Fix | Delete
$query = htmlspecialchars( $this->last_query, ENT_QUOTES );
[1842] Fix | Delete
[1843] Fix | Delete
printf(
[1844] Fix | Delete
'<div id="error"><p class="wpdberror"><strong>%s</strong> [%s]<br /><code>%s</code></p></div>',
[1845] Fix | Delete
__( 'WordPress database error:' ),
[1846] Fix | Delete
$str,
[1847] Fix | Delete
$query
[1848] Fix | Delete
);
[1849] Fix | Delete
}
[1850] Fix | Delete
}
[1851] Fix | Delete
[1852] Fix | Delete
/**
[1853] Fix | Delete
* Enables showing of database errors.
[1854] Fix | Delete
*
[1855] Fix | Delete
* This function should be used only to enable showing of errors.
[1856] Fix | Delete
* wpdb::hide_errors() should be used instead for hiding errors.
[1857] Fix | Delete
*
[1858] Fix | Delete
* @since 0.71
[1859] Fix | Delete
*
[1860] Fix | Delete
* @see wpdb::hide_errors()
[1861] Fix | Delete
*
[1862] Fix | Delete
* @param bool $show Optional. Whether to show errors. Default true.
[1863] Fix | Delete
* @return bool Whether showing of errors was previously active.
[1864] Fix | Delete
*/
[1865] Fix | Delete
public function show_errors( $show = true ) {
[1866] Fix | Delete
$errors = $this->show_errors;
[1867] Fix | Delete
$this->show_errors = $show;
[1868] Fix | Delete
return $errors;
[1869] Fix | Delete
}
[1870] Fix | Delete
[1871] Fix | Delete
/**
[1872] Fix | Delete
* Disables showing of database errors.
[1873] Fix | Delete
*
[1874] Fix | Delete
* By default database errors are not shown.
[1875] Fix | Delete
*
[1876] Fix | Delete
* @since 0.71
[1877] Fix | Delete
*
[1878] Fix | Delete
* @see wpdb::show_errors()
[1879] Fix | Delete
*
[1880] Fix | Delete
* @return bool Whether showing of errors was previously active.
[1881] Fix | Delete
*/
[1882] Fix | Delete
public function hide_errors() {
[1883] Fix | Delete
$show = $this->show_errors;
[1884] Fix | Delete
$this->show_errors = false;
[1885] Fix | Delete
return $show;
[1886] Fix | Delete
}
[1887] Fix | Delete
[1888] Fix | Delete
/**
[1889] Fix | Delete
* Enables or disables suppressing of database errors.
[1890] Fix | Delete
*
[1891] Fix | Delete
* By default database errors are suppressed.
[1892] Fix | Delete
*
[1893] Fix | Delete
* @since 2.5.0
[1894] Fix | Delete
*
[1895] Fix | Delete
* @see wpdb::hide_errors()
[1896] Fix | Delete
*
[1897] Fix | Delete
* @param bool $suppress Optional. Whether to suppress errors. Default true.
[1898] Fix | Delete
* @return bool Whether suppressing of errors was previously active.
[1899] Fix | Delete
*/
[1900] Fix | Delete
public function suppress_errors( $suppress = true ) {
[1901] Fix | Delete
$errors = $this->suppress_errors;
[1902] Fix | Delete
$this->suppress_errors = (bool) $suppress;
[1903] Fix | Delete
return $errors;
[1904] Fix | Delete
}
[1905] Fix | Delete
[1906] Fix | Delete
/**
[1907] Fix | Delete
* Kills cached query results.
[1908] Fix | Delete
*
[1909] Fix | Delete
* @since 0.71
[1910] Fix | Delete
*/
[1911] Fix | Delete
public function flush() {
[1912] Fix | Delete
$this->last_result = array();
[1913] Fix | Delete
$this->col_info = null;
[1914] Fix | Delete
$this->last_query = null;
[1915] Fix | Delete
$this->rows_affected = 0;
[1916] Fix | Delete
$this->num_rows = 0;
[1917] Fix | Delete
$this->last_error = '';
[1918] Fix | Delete
[1919] Fix | Delete
if ( $this->result instanceof mysqli_result ) {
[1920] Fix | Delete
mysqli_free_result( $this->result );
[1921] Fix | Delete
$this->result = null;
[1922] Fix | Delete
[1923] Fix | Delete
// Confidence check before using the handle.
[1924] Fix | Delete
if ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) {
[1925] Fix | Delete
return;
[1926] Fix | Delete
}
[1927] Fix | Delete
[1928] Fix | Delete
// Clear out any results from a multi-query.
[1929] Fix | Delete
while ( mysqli_more_results( $this->dbh ) ) {
[1930] Fix | Delete
mysqli_next_result( $this->dbh );
[1931] Fix | Delete
}
[1932] Fix | Delete
}
[1933] Fix | Delete
}
[1934] Fix | Delete
[1935] Fix | Delete
/**
[1936] Fix | Delete
* Connects to and selects database.
[1937] Fix | Delete
*
[1938] Fix | Delete
* If `$allow_bail` is false, the lack of database connection will need to be handled manually.
[1939] Fix | Delete
*
[1940] Fix | Delete
* @since 3.0.0
[1941] Fix | Delete
* @since 3.9.0 $allow_bail parameter added.
[1942] Fix | Delete
*
[1943] Fix | Delete
* @param bool $allow_bail Optional. Allows the function to bail. Default true.
[1944] Fix | Delete
* @return bool True with a successful connection, false on failure.
[1945] Fix | Delete
*/
[1946] Fix | Delete
public function db_connect( $allow_bail = true ) {
[1947] Fix | Delete
$this->is_mysql = true;
[1948] Fix | Delete
[1949] Fix | Delete
$client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
[1950] Fix | Delete
[1951] Fix | Delete
/*
[1952] Fix | Delete
* Set the MySQLi error reporting off because WordPress handles its own.
[1953] Fix | Delete
* This is due to the default value change from `MYSQLI_REPORT_OFF`
[1954] Fix | Delete
* to `MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT` in PHP 8.1.
[1955] Fix | Delete
*/
[1956] Fix | Delete
mysqli_report( MYSQLI_REPORT_OFF );
[1957] Fix | Delete
[1958] Fix | Delete
$this->dbh = mysqli_init();
[1959] Fix | Delete
[1960] Fix | Delete
$host = $this->dbhost;
[1961] Fix | Delete
$port = null;
[1962] Fix | Delete
$socket = null;
[1963] Fix | Delete
$is_ipv6 = false;
[1964] Fix | Delete
[1965] Fix | Delete
$host_data = $this->parse_db_host( $this->dbhost );
[1966] Fix | Delete
if ( $host_data ) {
[1967] Fix | Delete
list( $host, $port, $socket, $is_ipv6 ) = $host_data;
[1968] Fix | Delete
}
[1969] Fix | Delete
[1970] Fix | Delete
/*
[1971] Fix | Delete
* If using the `mysqlnd` library, the IPv6 address needs to be enclosed
[1972] Fix | Delete
* in square brackets, whereas it doesn't while using the `libmysqlclient` library.
[1973] Fix | Delete
* @see https://bugs.php.net/bug.php?id=67563
[1974] Fix | Delete
*/
[1975] Fix | Delete
if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
[1976] Fix | Delete
$host = "[$host]";
[1977] Fix | Delete
}
[1978] Fix | Delete
[1979] Fix | Delete
if ( WP_DEBUG ) {
[1980] Fix | Delete
mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
[1981] Fix | Delete
} else {
[1982] Fix | Delete
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
[1983] Fix | Delete
@mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
[1984] Fix | Delete
}
[1985] Fix | Delete
[1986] Fix | Delete
if ( $this->dbh->connect_errno ) {
[1987] Fix | Delete
$this->dbh = null;
[1988] Fix | Delete
}
[1989] Fix | Delete
[1990] Fix | Delete
if ( ! $this->dbh && $allow_bail ) {
[1991] Fix | Delete
wp_load_translations_early();
[1992] Fix | Delete
[1993] Fix | Delete
// Load custom DB error template, if present.
[1994] Fix | Delete
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
[1995] Fix | Delete
require_once WP_CONTENT_DIR . '/db-error.php';
[1996] Fix | Delete
die();
[1997] Fix | Delete
}
[1998] Fix | Delete
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function