0

I created a function in JavaScript that transform an 'image' file selected by user to dataURI. Then I passed it to a php script by POST method. The problem is when I try to save this information into MySQL as follows

$him = $_POST["him"];
$req = $pdo->prepare("INSERT INTO `cr`.`chercheur` 
                    (`cin`, `nom`, `prenom`, `statut`, 
                     `tel1`,  `email`, `tof`, `etat`) 
                VALUES (?, ?, ?, ?, ?,?, ?, '0')");
$req->execute(array($cin,$nom,$prenom,$statu,$tel,$mail,$him));

I get an error below.

Warning: PDOStatement::execute(): MySQL server has gone away in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\CR\module\compte\demande\dem_user.php on line 89

Warning: PDOStatement::execute(): Error reading result set's header in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\CR\module\compte\demande\dem_user.php on line 89 SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

thor
  • 21,418
  • 31
  • 87
  • 173
  • As it says, your MySQL server is not available: see http://stackoverflow.com/questions/1644432/mysql-server-has-gone-away-in-exactly-60-seconds – sitilge May 02 '15 at 20:17

2 Answers2

1

This is probably due to the size of the images you're trying to store being large enough to overflow the maximum packet size configured for MySQL. Try changing the max_allowed_packet setting in my.ini in your MySQL installation folder (under the [mysqld] section) to a larger value.

You can check the current value (and if the new value you set has taken effect) with the following SQL command:

SHOW VARIABLES LIKE 'max_allowed_packet';

See this page: http://dev.mysql.com/doc/refman/5.0/en/gone-away.html

You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section B.5.2.10, “Packet Too Large”.

planetbeing
  • 310
  • 3
  • 6
1

The problem is that dataURI in JavaScript side use the "+" to concat and PHP use "." so the solution is to substitue "+" to "."