From 03e3c63785470c3f2a4c04e669ba71d90d545d45 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Tue, 28 Oct 2014 17:27:58 +0100
Subject: [PATCH] hotline #17328 sql_server_gone_away

increase session wait_timeout
---
 cosmogramme/php/classes/classe_sql.php | 29 +++++++++++++++-----------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/cosmogramme/php/classes/classe_sql.php b/cosmogramme/php/classes/classe_sql.php
index edc9fb786ad..58c181186f9 100644
--- a/cosmogramme/php/classes/classe_sql.php
+++ b/cosmogramme/php/classes/classe_sql.php
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with AFI-OPAC 2.0; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //   SQL qui s'appuie sur PDO
@@ -33,17 +33,22 @@ class sql
 
 // ---------------------------------------------------
 // Constructeur : connexion à la base
-// ---------------------------------------------------	
+// ---------------------------------------------------
 	function __construct($server,$user,$pwd,$base)
 	{
 		$dns="mysql:dbname=".$base.";host=".$server;
-		try {	$this->hpdo=new PDO($dns,$user,$pwd); }
-		catch (PDOException $e) { afficherErreur('<b><font color="red">Impossible de se connecter au moteur Mysql</font></b><br>'.$e->getMessage());}
+		try {
+			$this->hpdo=new PDO($dns,$user,$pwd); }
+		catch (PDOException $e) {
+			afficherErreur('<b><font color="red">Impossible de se connecter au moteur Mysql</font></b><br>'.$e->getMessage());
+		}
 		$this->hpdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+		 $query = $this->hpdo->prepare("set session wait_timeout=10000");
+		 $query->execute();
 	}
 // ---------------------------------------------------
 // Resultat pour 1 seule colonne et 1 seul enreg
-// ---------------------------------------------------	
+// ---------------------------------------------------
 	public function fetchOne($req)
 	{
 		try
@@ -102,8 +107,8 @@ class sql
 // ---------------------------------------------------
 	public function execute($req)
 	{
-		try 
-		{ 
+		try
+		{
 			$nombre=$this->hpdo->exec($req);
 			return $nombre;
 		}
@@ -142,7 +147,7 @@ class sql
 	public function insert($table,$data)	{
 		$cols = implode(',', array_keys($data));
 		$statement = isset($this->statements[$table][$cols])
-			? $this->statements[$table][$cols] 
+			? $this->statements[$table][$cols]
 			: $this->statements[$table][$cols] = $this->createInsertPrepareStatement($table, $data);
 
 		foreach($data as $col => $valeur)
@@ -163,7 +168,7 @@ class sql
 		$placeholders = array();
 		foreach($cols as $col)
 			$placeholders []= ':'.$col;
-		return $this->hpdo->prepare('insert into '.$table.' ('.implode(',', $cols).') VALUES ('.implode(',', $placeholders).')'); 
+		return $this->hpdo->prepare('insert into '.$table.' ('.implode(',', $cols).') VALUES ('.implode(',', $placeholders).')');
 	}
 
 // ---------------------------------------------------
@@ -206,7 +211,7 @@ class sql
 // ---------------------------------------------------
 	public function ignoreErreurs($mode)
 	{
-		$this->ignore_erreurs=$mode; 
+		$this->ignore_erreurs=$mode;
 	}
 // ---------------------------------------------------
 // Traitement des erreurs
@@ -235,10 +240,10 @@ class sql
 			$msg.=" - <b>Fonction : </b>". $lig["function"].BR;
 		}
 		$msg.='</div>';
-		
+
 		// Afficher l'erreur
 		if( getVariable("sql_debug") == 1) print('</center>'.$msg);
-		
+
 		// On log l'erreur
 		if(!$this->log) $this->log=new Class_log("sql",false);
 		$this->log->open(true);
-- 
GitLab