2015-05-02 55 views
0

我在JavaScript中創建了一個將用戶選擇的'圖像'文件轉換爲dataURI的函數。然後我通過POST方法將它傳遞給一個php腳本。問題是當我試圖將這些信息保存到MySQL中時,如下所示:將dataURI圖像從JavaScript解析到PHP

$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)); 

我在下面得到一個錯誤。

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

+0

正如它所說,您的MySQL服務器不可用:請參閱http://stackoverflow.com/questions/1644432/mysql-server-has-gone-away-in-exactly-60-seconds – sitilge

回答

1

的問題是JavaScript端的dataURI使用「+」來連接,而PHP使用「。」所以解決方法是將「+」替換爲「。」。

1

這可能是由於您嘗試存儲的映像的大小足夠大以致超過爲MySQL配置的最大數據包大小。嘗試在您的MySQL安裝文件夾(位於[mysqld]部分)中將my.ini中的max_allowed_packet設置更改爲更大的值。

您可以查看當前值(如果設置新的值已生效)用下面的SQL命令:

SHOW VARIABLES LIKE 'max_allowed_packet'; 

看到這個頁面: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」.

+0

其工作thx –