0

So I'm having the same problem as the folks here:

But I didn't see any genuine solutions to the problem besides the hack the guy posted in the first one to split the text up. The scripts have been tested and save to the database fine when it's a small amount of text, and the php script can save the largetext to a txt file fine as well. So the problem is somewhere on the Database side.

EDIT: The field I am posting to is already set to LONGTEXT

Here are my scripts:

post.php

<?php
$data=$_POST["SData"];  //Around 76kb of text 
$rName=$_POST["regName"];

include_once './db_functions.php';
$db = new DB_Functions();
$db->insertText($rName, $data);
?>

db_functions.php

//Insert Text Data into DB
public function insertText($regId, $sdata) {
    try {
        mysql_query("UPDATE users SET textdata = '$sdata' WHERE id = '$regId'");
    }
    catch (PDOException $e) {
        $output = 'Error performing update: ' . $e->getMessage();
    }

}

I have the following questions:

  1. What is the maximum datasize(amount of characters?) that I can send via PHP to a MySQL database? All the text i'm attempting to post is not necessary, so I could potentially limit it before I POST it. (But the more, the better)

  2. Is there an actual solution where I could send large datachunks over PHP?
    Potentially using 'the mysqli_stmt::send_long_data' found here: http://php.net/manual/en/mysqli-stmt.send-long-data.php ? Are there any examples of this being used that aren't just in the manual?

Any help would be greatly appreciated, thanks!!

Community
  • 1
  • 1
  • 4
    the only limits are PHP's `memory_limit`, and mysql's `max_allowed_packet` for the php->mysql communications channel. – Marc B May 30 '14 at 21:14
  • Odd, just checked my PHP memory_limit which was set at 128M and my mysql max allowed packed was max_allowed_packet = 1M. Since my text file is around 77kb I don't think this is the problem? –  May 30 '14 at 21:32
  • What error are you getting when you try to save a large text? – Barmar May 30 '14 at 21:39
  • Why are you catching a PDO exception when you're not using PDO? – Barmar May 30 '14 at 21:40
  • Better question: why aren't you using PDO? – Barmar May 30 '14 at 21:41
  • 1
    Are you sure `$sdata` doesn't contain any apostrophe characters? That would cause a syntax error when you substitute into the query, since you don't call `mysql_real_escape_string()`. – Barmar May 30 '14 at 21:42
  • Thanks....it was due to the escape_string not being there. You're a hero man. –  May 30 '14 at 22:02
  • Do your debugging using a normal browser, so you can use the developer tools. Or have the PHP code use `error_log()` to print `mysql_error()`, then check the PHP error log on the server. – Barmar May 30 '14 at 22:06
  • 1
    Why did you add `mysql_real_escape_string` to the question? Now it looks like you're correctly using it, so my answer makes no sense. Don't fix the bug in the question, it's supposed to stand for posterity to show what the problem was, and the answer shows the solution. – Barmar May 30 '14 at 22:08

2 Answers2

2

If you're using the obsolete mysql extension, you need to escape the data:

$sdata = mysql_real_escape_string($_POST['SData']);

It would be better to use PDO or mysqli and use prepared statements.

Barmar
  • 741,623
  • 53
  • 500
  • 612
1

Check your max_allowed_packet paramter on your MySQL server, it will be the max value in bytes what MySQL will receive in query.

PHP has memory_limit configuration parameter as well.

Ivan Cachicatari
  • 4,212
  • 2
  • 21
  • 41