I have got a real problem... I have a database system (MySQL) which has a front-end written in PHP.

One of the functions of the front-end is to allow file-upload into the MySQL database, as BLOBS.

I seem to have hit some unpassable limit of approximate 10mb (9mb works, 13 mb fails), of the files that I can get into the database.

I have upped the MAX_PACKET_SIZE in MySQL, and the wait timeout, I have upped the max execution, max input, and memory limits of PHP, all to no avail.

The field in the database is a LONGBLOB, so should be OK.

Can anyone pleeeease tell me that I am missing something obvious somewhere. I understand MySQL is supposed to be handle, theoretically BLOB sizes of up to 2 gig!

Here is the snippet of code that does the uploading... I know this code works, as it works with smaller files...(up to approx 9mb)

$attsql = "insert into attachments values(";
$attsql .= $current_id.",'".$filename."','".$description."','".$filetype."','".$filesize."','".$data."')";
mysql_connect("host", "user", "password");
mysql_select_db("database");
mysql_query($attsql);

If I output the $data to screen, it all seems to be there, but I think MySQL is just plain rejecting the query when the BLOB is big, as nothing is being inserted into the database. The PHP process runs, sends the query to MySQL, and, from that point, nothing happens. Thats how it seems to be.

I can't help thinking this is just a configuration of MySQL that I have not quite gotten right, but I sure can't find it!!

I am using PHP4 and MySQL 4.1

Please help, I'm losing sleep over it!!!!

    Hi,
    You could test the limits by taking a copy of one of the files that you want to insert, and editing with a good editor (like vim) to add the SQL command around the data. then piping it into the command line mysql tool?

    This will destroy the file, but at least you will know whether it is a mysql limit or a php one.

    mysql -h host -u user -ppassword dbname <file_to_test

    cheers

      Cheers for the tip, but I'm going to change the application to store the files as files in a fiel structure rather than in the db. I can just see too many problems lying ahead if even if I fixed the one I have now!

        Consider using the PDO or mysqli functions with a bound parameter to pass blobs in. This is much safer and uses a different protocol (On MYSQL 4.1+) to pass stuff separately from the query which avoids this limit.

        Of course you'll need to upgrade from PHP4 to do this, but PHP4 is ancient anyway.

        Mark

          Write a Reply...