Re: Large insert queries
| From: | Michael Kimsal | Date: | Mon, 02 Oct 2000 21:20:32 +0000 |
| Subject: | Re: Large insert queries | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18316@lists.php.net to get a copy of this message | ||
You could gzip then encode the file, then insert it, depending on
what you were going to do later.
echo strlen($data)."<br>\n";
$data = base64_encode(gzcompress($data,9));
echo strlen($data)."<br>\n";
That should show you a big savings.
To get it back ...
$data = gzuncompress(base64_decode($data));
Timo Haimi wrote:
> Hi,
>
> I've got a problem while inserting a large blob to database. When the
> filesize is over 1 MB, the mysql server says it's gone away..
> The code is more or less like this;
>
> $fp=fopen("datafile","r");
> $data=fread($fp,filesize("datafile"));
> fclose($fp);
>
> $data=str_replace("'","''",$data);
> $data=str_replace("\\","\\\\",$data);
>
> $sql="insert into data(id,data) values (1,'$data')";
> mysql_query($sql);
>
> The code works with, lets say, 900Kb files but when we go over megabyte the
> server dies. Does it take too long to write the insert clause to server or
> something like that? If this is the case, how to make it faster?
>
> -Timo
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
==========================
Michael Kimsal
http://www.tapinternet.com
734-480-9961