FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


putting image to mysql. "MySQL Gone Away"





imagefree
I am trying to put all my dir images to mysql table, but it shows the following error after futting 1 image to db:


Code:
MySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone awayMySQL server has gone away........

and continues as long as it finds images in dir.


here is the script. What more should i do with this script?

Code:
<?
$dbcnx = @mysql_connect("localhost", "root", "pass");
if (!$dbcnx)
{
echo( "<p>connection to database server failed!</p>");
exit();
}
if (! @mysql_select_db("base64imgdb") )
{
echo( "<p>Image Database Not Available!</p >" );
exit();
}


$path = "hq";
$dir_handle = opendir($path) or die("Unable to open directory $path");
while ($file = readdir($dir_handle))
{
   //$filetyp = substr($file, -3);
   if ($file != '.' AND $file != '..')
   {
      $handle = fopen($path . "/" . $file,'r');
      $file_content = fread($handle,filesize($path . "/" . $file));
      fclose($handle);
      
      $encoded = chunk_split(base64_encode($file_content));
      $sql = "INSERT INTO images SET sixfourdata='$encoded'";
      
      mysql_query($sql);
      echo mysql_error();
      //echo "still";
   }
}
closedir($dir_handle);
echo("complete");
?>
rvec
not entirely sure but I think mysql and files are both opened with the same code in the backend of PHP, and in your script it mixes up the handlers.

edit: oh can't be that, then it wouldn't insert the first image. But you could try to use a link identifier for the mysql connection. The link identifier is returned with by mysql_connect and can be used as a second parameter in mysql_query.
imagefree
i will try and then reply here.
can you tell me:
whether it is resource feasible to put images in table for a large image hosting site like thousands around here? (my normal page execution time is .04 sec with about 8 queries, but querying this images table takes .4 seconds to show 30 rows just, and there are only about 50 records yet.)

Does huge size of a table affect the performance of other tables in the same mysql database?


What may be your prefered way to handle images if you would develop a script for image hosting site? (file system or database).

thanks
imagefree
i have tried putting $dbcnx but doesnt work.

I made a little change to script. I added the mysql_connect and select_db functions inside while (before querying) and closed the connection after echoing the mysql_error.
Here is the new pattren of errors.


Code:
done
MySQL server has gone awaydone
done
done
done
done
done
done
done
done
done
done
done
done
done
done
done
MySQL server has gone awaydone
done
done
done
done
done
done
done
MySQL server has gone awaydone
done
done
MySQL server has gone awaydone
done
MySQL server has gone awaydone
done
done
done
done
done
done
done
MySQL server has gone awaydone
done
done
done
done
done
done
MySQL server has gone awaydone
MySQL server has gone awaydone
done
done
done
done
complete

One interesting thing about it is that while i refreshed the page many time, the sequance of error remained same. Means its not just that mysql goes busy, there is something wrong otherwise.
imagefree
i have searched a lot of sites and found that i need to change max_allowed_packet value in my.cfg of my.ini file in mysql installation dir.

i have no such file. Strange!!!!! Very Happy
I m using XAMPP.
badai
it means connection to mysql timed out.

to use blob, make change to you php.ini:

max_execution_time 300
post_max_size 64M
upload_max_filesize 64M
memory_limit 64M

and my.cnf:
max_allowed_packet = 32M

notice the size double in PHP? also, when you increase the max_allowed_packet, you might want to increase max_execution_time in PHP.

to avoid user frustration, you might want to add this to your upload form:
<input name="MAX_FILE_SIZE" value="33000000" type="hidden">
imagefree
imagefree wrote:
i will try and then reply here.
can you tell me:
whether it is resource feasible to put images in table for a large image hosting site like thousands around here? (my normal page execution time is .04 sec with about 8 queries, but querying this images table takes .4 seconds to show 30 rows just, and there are only about 50 records yet.)

Does huge size of a table affect the performance of other tables in the same mysql database?


What may be your prefered way to handle images if you would develop a script for image hosting site? (file system or database).

thanks

what do u say about these questions?
kv
I would never use a database to store large number of files. File system is efficient in handling files, database in handling data. The best way is to store the files in file system, and store the name,path,title and other details of the files as records in db table. For display purposes [like listing of files/images in a particular category, etc] use database, and when it comes to file retrieval, take path/name from database and read the file from file system.
Related topics
Do you like cooking?
Tutorial: Photoshop
Mysql has gone away
Error connecting to mysql ; please help
Small addictive game
NEW DOMAIN - Best Site on Science!!!
This is so absurd, i could not make it up
General error - mysql server has gone away.
Help! Some problems in CPanel, database all of a sudden.
Database error
CRT monitor problem - horizontal lines
Error while opening a topic
Server 4 move
phpBB : Critical Error Events
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.