• Resolved Andry

    (@blackstar1991)


    I have a problem with update data in WordPress Data base. I get fetch request, that got me 2,4Mb information, but when i try to push it into custom table by function:

    add_action( 'wp_ajax_updateDB', 'updateDataBase' );
    function updateDataBase(){
        global $wpdb;
        $table_name = $wpdb->get_blog_prefix() . 'sports_viewer';
        $wpdb->update(
            $table_name,
            array(
                'json' => $_POST['text'],
                'object_last_modified' => current_time( 'mysql' ),
            ),
             array('id' => 1),
             array('%s'),
        );
        wp_die();
    }
    

    It’s pushing only 16kB of information. I can’t find fow to fix it.
    *cell’json’ has type – MEDIUMTEXT

    • This topic was modified 2 years, 4 months ago by Andry.
    • This topic was modified 2 years, 4 months ago by Andry.
    • This topic was modified 2 years, 4 months ago by Andry.
Viewing 10 replies - 1 through 10 (of 10 total)
  • I would first recommend debugging what arrives at the server via AJAX. For this you can simply output values via var_dump() and can look at the response in the network tab of your browser.

    Example:

    function updateDataBase(){
     var_dump($_POST);wp_die();
    }

    If you see here that ‘text’ is already truncated at this point, then your AJAX request would be responsible.

    Thread Starter Andry

    (@blackstar1991)

    I see Headers parameter Content-Length: 2059630 in Chrome DevTools, but var_dump($_POST); show me nothing in php function

    What do you mean by “show me nothing in php function”? You should at least see an output like array() {} if the POST request is empty.

    Thread Starter Andry

    (@blackstar1991)

    On the html page, when I started AJAX request pushing on a button I see nothing changes;

    
    function updateDataBase(){
        global $wpdb;
        $table_name = $wpdb->get_blog_prefix() . 'sports_viewer';
        var_dump($_POST . ' dick');
        print_r($_POST);
        wp_die();
    }
    

    NO array.

    Then the function will not be executed. Are you sure it is exactly this one? What comes back as response of the AJAX request?

    Thread Starter Andry

    (@blackstar1991)

    I see request https://joxi.ru/Rmzy38McV9ZzXr
    But when I show result AJAX in console I got –> https://joxi.ru/VrwxZ1JcgldQjm

    I guess in your first screenshot you can see the post content. But this is not an array but a string, which is strange. Have a look at how you define the AJAX request in JavaScript.

    Thread Starter Andry

    (@blackstar1991)

    My js code look like

    
    async function getData() {
            let response = await fetch('https://api1.test.com/');
            if (!response.ok) {
                const message = <code>An error has occured: ${response.status}</code>;
                throw new Error(message);
            }
            let result = response.json();
            return await result
        }
    $('#btn_update').click(function(){
    
            getData().then((data) => {
                const sportsJsonString =  JSON.stringify(data, null, "\t");
                console.log("sportsJsonString", sportsJsonString);
                fetch(ajaxurl, {
                    method: 'POST',
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    body: <code>action=updateDB&text=${sportsJsonString}</code>
                })
                    .then((data) =>{
                        $('#btn_update').text('Повторно обновить');
                    })
                    .catch(err => console.error(err));
            })
        });
    

    Why strange for you, that variable type of ‘sportsJsonString’ – string? If I push ‘data’ variable into table cell, I got [object Object] in this json cell.

    • This reply was modified 2 years, 4 months ago by Andry.
    Thread Starter Andry

    (@blackstar1991)

    During testing, I realized that the browser does not allow to write >415kB to the database (Chrome or FF makes no difference) It’s browser problem.

    You can check it if you interrupt operations when accessing the file `wp-admin/admin-ajax.php’

    The browser does not know about a database running only on the server. I am not even aware of such a limit. Where did you get this value?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘problems with database Full update’ is closed to new replies.