Make WordPress Core

Ticket #41956: 41956.4.diff

File 41956.4.diff, 4.7 KB (added by munyagu, 7 years ago)

remove unrelated fixes

  • src/wp-includes/wp-db.php

     
    7777        public $last_error = '';
    7878
    7979        /**
     80         * The last error code during query.
     81         *
     82         * @since
     83         * @var int
     84         */
     85        protected $last_err_no = 0;
     86
     87        /**
     88         * The last error message during query.
     89         *
     90         * @var string
     91         */
     92        protected $last_err_msg = '';
     93
     94        /**
    8095         * Amount of queries made
    8196         *
    8297         * @since 1.2.0
     
    13111326        public function print_error( $str = '' ) {
    13121327                global $EZSQL_ERROR;
    13131328
    1314                 if ( !$str ) {
    1315                         if ( $this->use_mysqli ) {
    1316                                 $str = mysqli_error( $this->dbh );
    1317                         } else {
    1318                                 $str = mysql_error( $this->dbh );
    1319                         }
     1329                if ( '' === $str ) {
     1330                        $str = $this->last_err_msg;
    13201331                }
    1321                 $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str );
     1332                $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str, 'error_no' => $this->last_err_no );
    13221333
    13231334                if ( $this->suppress_errors )
    13241335                        return false;
     
    13681379        }
    13691380
    13701381        /**
     1382         * Retrieve error code from the last database error.
     1383         *
     1384         * @since
     1385         * @return int Error code, Zero on no error has occurred.
     1386         */
     1387        public function get_err_no(){
     1388                return $this->last_err_no;
     1389        }
     1390
     1391        /**
     1392         * Retrieve error message from the last database error.
     1393         *
     1394         * @since
     1395         * @return string Error message, empty string on no error has occurred.
     1396         */
     1397        public function get_err_msg(){
     1398                return $this->last_err_msg;
     1399        }
     1400
     1401        /**
     1402         * Retrieve error info from the last database error.
     1403         *
     1404         * @since
     1405         * @return array|bool Array containing error no and message, false on no error has occurred.
     1406         */
     1407        public function get_last_error(){
     1408                if ( $this->last_err_no > 0 ){
     1409                        return array(
     1410                                'error_no' => $this->last_err_no,
     1411                                'error_message' => $this->last_err_msg,
     1412                        );
     1413                } else {
     1414                        return false;
     1415                }
     1416        }
     1417
     1418        /**
    13711419         * Enables showing of database errors.
    13721420         *
    13731421         * This function should be used only to enable showing of errors.
     
    14301478                $this->col_info    = null;
    14311479                $this->last_query  = null;
    14321480                $this->rows_affected = $this->num_rows = 0;
     1481                $this->last_err_no   = 0;
     1482                $this->last_err_msg  = '';
    14331483                $this->last_error  = '';
    14341484
    14351485                if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
     
    17721822                $this->_do_query( $query );
    17731823
    17741824                // MySQL server has gone away, try to reconnect.
    1775                 $mysql_errno = 0;
     1825                $this->last_err_no = 0;
    17761826                if ( ! empty( $this->dbh ) ) {
    17771827                        if ( $this->use_mysqli ) {
    17781828                                if ( $this->dbh instanceof mysqli ) {
    1779                                         $mysql_errno = mysqli_errno( $this->dbh );
     1829                                        $this->last_err_no = mysqli_errno( $this->dbh );
    17801830                                } else {
    17811831                                        // $dbh is defined, but isn't a real connection.
    17821832                                        // Something has gone horribly wrong, let's try a reconnect.
    1783                                         $mysql_errno = 2006;
     1833                                        $this->last_err_no = 2006;
    17841834                                }
    17851835                        } else {
    17861836                                if ( is_resource( $this->dbh ) ) {
    1787                                         $mysql_errno = mysql_errno( $this->dbh );
     1837                                        $this->last_err_no = mysql_errno( $this->dbh );
    17881838                                } else {
    1789                                         $mysql_errno = 2006;
     1839                                        $this->last_err_no = 2006;
    17901840                                }
    17911841                        }
    17921842                }
    17931843
    1794                 if ( empty( $this->dbh ) || 2006 == $mysql_errno ) {
     1844                if ( empty( $this->dbh ) || 2006 == $this->last_err_no ) {
    17951845                        if ( $this->check_connection() ) {
    17961846                                $this->_do_query( $query );
    17971847                        } else {
     
    17981848                                $this->insert_id = 0;
    17991849                                return false;
    18001850                        }
    1801                 }
    1802 
    1803                 // If there is an error then take note of it.
    1804                 if ( $this->use_mysqli ) {
    1805                         if ( $this->dbh instanceof mysqli ) {
    1806                                 $this->last_error = mysqli_error( $this->dbh );
     1851                } elseif ( 0 !== $this->last_err_no ) {
     1852                        // If there is an error then take note of it.
     1853                        if ( $this->use_mysqli ) {
     1854                                if ( $this->dbh instanceof mysqli ) {
     1855                                        $this->last_error   = mysqli_error( $this->dbh );
     1856                                        $this->last_err_msg = mysqli_error( $this->dbh );
     1857                                } else {
     1858                                        $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
     1859                                }
    18071860                        } else {
    1808                                 $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
     1861                                if ( is_resource( $this->dbh ) ) {
     1862                                        $this->last_error   = mysql_error( $this->dbh );
     1863                                        $this->last_err_msg = mysql_error( $this->dbh );
     1864                                } else {
     1865                                        $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
     1866                                }
    18091867                        }
    1810                 } else {
    1811                         if ( is_resource( $this->dbh ) ) {
    1812                                 $this->last_error = mysql_error( $this->dbh );
    1813                         } else {
    1814                                 $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
    1815                         }
    1816                 }
    18171868
    1818                 if ( $this->last_error ) {
    18191869                        // Clear insert_id on a subsequent failed insert.
    18201870                        if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) )
    18211871                                $this->insert_id = 0;