Jump to content

Inserting large strings into a MySQL DB


sirdavidoff

Recommended Posts

Hi guys,

 

I have a mysql database, in which I want to store some files as longblobs. I'm using PEAR to connect to the DB. So far so good... until the files get over 16MB; the server takes ages to do the query and finally breaks without actually performing it.

 

I'm reading in the file to a variable in memory and outputting that variable in the SQL statement, e.g.

"INSERT INTO table VALUES('$fileContents');"

 

What's weird (and what makes me think it's not a max_allowed_packet problem) is that if I use MySQL's LOAD_FILE() function it works fine:

"INSERT INTO table VALUES(LOAD_FILE('$pathToFile'));"

 

Any ideas?

 

David

Link to comment
Share on other sites

Unfortunately this is part of a complex application, and it's not really feasible to change the way that the files are stored now. I have found other posts on the internet from people who have had similar problems and ended up giving up though... someone must know the answer!

Link to comment
Share on other sites

Hi frost110 - you're right, it sounds like a PHP memory limit problem and indeed the default memory_limit for my version of PHP (4.4.4) is 16MB.

 

However, I have tried increasing this and it doesn't seem to make any difference. It is interesting to note that the memory_limit variable does not appear in phpInfo() - does this mean that there is no limit set by PHP?

 

Thanks for your help  :)

Link to comment
Share on other sites

Check the php.ini for the max post size. Most of the time it is between 8-16 mb. you can change that at the top of your script by using ini_set like this:

 

ini_set('max_upload_size', '300000');

 

ini_set('max_post_size', '300000');

 

You can try different size limits to get different results.

 

They should come right after you opening tag before anyting is sent to the page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.