0

I have a very large matrix 1328x1328 and I'm trying to store the upper triangle (it is symmetrical) of it to the database as LONGTEXT. In JavaScript I serialize it: JSON.stringify(matrix) (serialized string length 16744056 characters) and send it to the server using ajax:

$.ajax({
      type: "PUT",
      url: 'post-user-matrix.php',
      data: JSON.stringify(matrix),
      contentType: "application/json"
    });

It arrives to PHP with no problems, but from there I want to save it to the database table

u_id(INT) | matrix_json (LONGTEXT)

The PHP script that should send the data to the database look like this:

$user_id = getUserID();
$matrix = file_get_contents("php://input");

if ($insert_stmt = $mysqli->prepare("INSERT INTO users_matrix (u_id, matrix_json) VALUES (?,?)")) {
    $null = NULL;
    $insert_stmt->bind_param('is',$user_id, $null);

    $matrixchunks = str_split($matrix, 8192);

    for ($i=0 ; $i < count($matrixchunks) ; $i++) {
        $insert_stmt->send_long_data(1, $matrixchunks[$i] );
    }

    $insert_stmt->execute(); 

}

I tried to use send_long_data relying on PHP documentation, but the script gives no errors and doesn't send anything to the database.

Joop
  • 3,706
  • 34
  • 55
Jackstick
  • 89
  • 1
  • 11
  • Do you have PHP errors turned on? – Danny Kopping May 02 '15 at 10:53
  • This is almost certainly a `max_post_size` issue http://stackoverflow.com/questions/6135427/increasing-the-maximum-post-size – Danny Kopping May 02 '15 at 10:54
  • Here - $insert_stmt->bind_param('is',$user_id, $null); replace is by ib, because it is blob data, not string - flag is b not s – Kancho Iliev May 02 '15 at 10:55
  • `error_reporting(E_ALL); ini_set('display_errors', 1);` It should show errors. Also tried it with ib, still nothing. Could be `max_post_size`, but shouldn't sending smaller chunks resolve that? – Jackstick May 02 '15 at 11:09

1 Answers1

0

I think the problem is in flags - has to be ib, not is

 $insert_stmt->bind_param('ib',$user_id, $null);

It can be seen on php documentation sample here: http://php.net/manual/en/mysqli-stmt.send-long-data.php

Kancho Iliev
  • 701
  • 5
  • 13