diff --git a/htdocs/core/modules/mailings/contacts1.modules.php b/htdocs/core/modules/mailings/contacts1.modules.php
index 3f8df87cd7acf9d1d90b7ce5dc4fa7208811ac97..5d2183769835c0bb9778b8854ed95302681ed4b0 100644
--- a/htdocs/core/modules/mailings/contacts1.modules.php
+++ b/htdocs/core/modules/mailings/contacts1.modules.php
@@ -85,7 +85,7 @@ class mailing_contacts1 extends MailingTargets
 	 *	For example if this selector is used to extract 500 different
 	 *	emails from a text file, this function must return 500.
 	 *
-	 *  @param	string	$sql		Requete sql de comptage
+	 *  @param		string	$sql		Requete sql de comptage
 	 *	@return		int
 	 */
 	function getNbOfRecipients($sql='')
diff --git a/htdocs/core/modules/mailings/contacts2.modules.php b/htdocs/core/modules/mailings/contacts2.modules.php
index fe49ce56b35eb77d2a642b842be03f92008cacf9..b1e22110f5e467c17eb4b943b8348b432cea63a9 100644
--- a/htdocs/core/modules/mailings/contacts2.modules.php
+++ b/htdocs/core/modules/mailings/contacts2.modules.php
@@ -152,7 +152,7 @@ class mailing_contacts2 extends MailingTargets
     /**
      * 		Return here number of distinct emails returned by your selector.
      *
-     *		@param	string	$sql		Requete sql de comptage
+     *		@param		string	$sql		Requete sql de comptage
      * 		@return		int
      */
     function getNbOfRecipients($sql='')
diff --git a/htdocs/core/modules/mailings/contacts3.modules.php b/htdocs/core/modules/mailings/contacts3.modules.php
index 926402910880378a4e2f6a923c05f214329bf39b..feeb0a2cb556b1ffd5e993e69b2eacfd5ea6bae9 100644
--- a/htdocs/core/modules/mailings/contacts3.modules.php
+++ b/htdocs/core/modules/mailings/contacts3.modules.php
@@ -157,7 +157,7 @@ class mailing_contacts3 extends MailingTargets
     /**
      *		Return here number of distinct emails returned by your selector.
      *
-     *		@param	string	$sql		Requete sql de comptage
+     *		@param		string	$sql		Requete sql de comptage
      *		@return		int		Number of recipients
      */
     function getNbOfRecipients($sql='')
diff --git a/htdocs/core/modules/mailings/contacts4.modules.php b/htdocs/core/modules/mailings/contacts4.modules.php
index 59355b372fe54e9bab1871dd1d95a94f702b0249..c0a1c59c01cd506f03cfaae91558e5985933f611 100644
--- a/htdocs/core/modules/mailings/contacts4.modules.php
+++ b/htdocs/core/modules/mailings/contacts4.modules.php
@@ -158,7 +158,7 @@ class mailing_contacts4 extends MailingTargets
     /**
      *		Return here number of distinct emails returned by your selector.
      *
-     *		@param	string	$sql		Requete sql de comptage
+     *		@param		string	$sql		Requete sql de comptage
      *		@return		int		Number of recipients
      */
     function getNbOfRecipients($sql='')
diff --git a/htdocs/core/modules/mailings/example.modules.php b/htdocs/core/modules/mailings/example.modules.php
index a7eb1b0b839b25530b3adbf1f1679452ddb6e8de..428285fb20b8bb13966133306a345dd477137671 100644
--- a/htdocs/core/modules/mailings/example.modules.php
+++ b/htdocs/core/modules/mailings/example.modules.php
@@ -100,8 +100,8 @@ class mailing_example extends MailingTargets
      *	For example if this selector is used to extract 500 different
      *	emails from a text file, this function must return 500.
      *
-     *  @param	string	$sql		Requete sql de comptage
-     *	@return		int
+     *  @param		string		$sql		Requete sql de comptage
+     *	@return		int|string				Number of recipient or '?'
      */
     function getNbOfRecipients($sql='')
     {
diff --git a/htdocs/core/modules/mailings/fraise.modules.php b/htdocs/core/modules/mailings/fraise.modules.php
index dd6e18dfa91edd16ab4af3057f6a8d683e36d044..69b018080b84d401aaa86ee355b135b0a232d387 100644
--- a/htdocs/core/modules/mailings/fraise.modules.php
+++ b/htdocs/core/modules/mailings/fraise.modules.php
@@ -86,8 +86,8 @@ class mailing_fraise extends MailingTargets
 	 *	For example if this selector is used to extract 500 different
 	 *	emails from a text file, this function must return 500.
 	 *
-	 *  @param	string	$sql		Requete sql de comptage
-	 *	@return		int			Nb of recipients
+	 *  @param		string		$sql		Requete sql de comptage
+	 *	@return		int						Nb of recipients
 	 */
     function getNbOfRecipients($sql='')
     {
diff --git a/htdocs/core/modules/mailings/framboise.modules.php b/htdocs/core/modules/mailings/framboise.modules.php
index c647466e79649bdf1710ad11cf3473e7f31442da..e25ffad5f1b618e2d4b0aa41752eaa59924e6c10 100644
--- a/htdocs/core/modules/mailings/framboise.modules.php
+++ b/htdocs/core/modules/mailings/framboise.modules.php
@@ -150,8 +150,8 @@ class mailing_framboise extends MailingTargets
 	 *	For example if this selector is used to extract 500 different
 	 *	emails from a text file, this function must return 500.
 	 *
-	 *  @param	string	$sql		Requete sql de comptage
-	 *	@return		int			Nb of recipients
+	 *  @param		string	$sql		Requete sql de comptage
+	 *	@return		int					Nb of recipients
 	 */
 	function getNbOfRecipients($sql='')
 	{
diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php
index 5561526a7fff6e084e8a7122ed0e6ee72eda5644..2508440c1478b00a0f36229fa035d64df6b6a12b 100644
--- a/htdocs/core/modules/mailings/modules_mailings.php
+++ b/htdocs/core/modules/mailings/modules_mailings.php
@@ -72,8 +72,8 @@ class MailingTargets    // This can't be abstract as it is used for some method
     /**
      * Retourne nombre de destinataires
      *
-     * @param      string	$sql        Requete sql de comptage
-     * @return     int       			Nb de destinataires si ok, < 0 si erreur
+     * @param      string	$sql        Sql request to count
+     * @return     int       			Nb of recipient, or <0 if error
      */
     function getNbOfRecipients($sql)
     {
@@ -85,7 +85,7 @@ class MailingTargets    // This can't be abstract as it is used for some method
         }
         else
         {
-        	$this->error=$this->db->error();
+        	$this->error=$this->db->lasterror();
             return -1;
         }
     }
diff --git a/htdocs/core/modules/mailings/thirdparties.modules.php b/htdocs/core/modules/mailings/thirdparties.modules.php
index df8ec79f9885826c45980f8eb5db674f20b736a6..222711cdf658ed070eca90ec4b3ae55568f238ef 100644
--- a/htdocs/core/modules/mailings/thirdparties.modules.php
+++ b/htdocs/core/modules/mailings/thirdparties.modules.php
@@ -157,7 +157,7 @@ class mailing_thirdparties extends MailingTargets
 	 *	emails from a text file, this function must return 500.
 	 *
 	 *  @param      string	$sql        Requete sql de comptage
-	 *	@return		int			Nb of recipients
+	 *	@return		int					Nb of recipients
 	 */
 	function getNbOfRecipients($sql='')
 	{
diff --git a/htdocs/core/modules/mailings/xinputfile.modules.php b/htdocs/core/modules/mailings/xinputfile.modules.php
index 777621fa432290e81aa3e3f4a9f6147a8cb0e871..7b6f8361d24d3f9d62f2f1dba20f59c7cb5d71f0 100644
--- a/htdocs/core/modules/mailings/xinputfile.modules.php
+++ b/htdocs/core/modules/mailings/xinputfile.modules.php
@@ -73,8 +73,8 @@ class mailing_xinputfile extends MailingTargets
 	 *	For example if this selector is used to extract 500 different
 	 *	emails from a text file, this function must return 500.
 	 *
-	 *  @param      string	$sql        Requete sql de comptage
-	 *	@return		int			'' means NA
+	 *  @param      string	$sql        Sql request to count
+	 *	@return		string				'' means NA
 	 */
 	function getNbOfRecipients($sql='')
 	{
diff --git a/htdocs/core/modules/mailings/xinputuser.modules.php b/htdocs/core/modules/mailings/xinputuser.modules.php
index 0d01aa539123aecf668271852246ef48d24dcf40..7832d1f6a938a40c2523d6f402d0e0f81d194b86 100644
--- a/htdocs/core/modules/mailings/xinputuser.modules.php
+++ b/htdocs/core/modules/mailings/xinputuser.modules.php
@@ -73,8 +73,8 @@ class mailing_xinputuser extends MailingTargets
 	 *	For example if this selector is used to extract 500 different
 	 *	emails from a text file, this function must return 500.
 	 *
-	 *  @param      string	$sql   Requete sql de comptage
-	 *	@return		int			'' means NA
+	 *  @param      string	$sql   	Sql request to count
+	 *	@return		string			'' means NA
 	 */
 	function getNbOfRecipients($sql='')
 	{
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index e4fe0c06e8e4f6f27cc7970309d8111599c016e4..d0b80db119030a1e8ca666541985bfe25a853923 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -111,17 +111,17 @@ function test_sql_and_script_inject($val, $type)
 /**
  * Security: Return true if OK, false otherwise.
  *
- * @param		string		$var		Variable name
- * @param		string		$type		1=GET, 0=POST, 2=PHP_SELF
- * @return		boolean					true if there is an injection
+ * @param		string			$var		Variable name
+ * @param		string			$type		1=GET, 0=POST, 2=PHP_SELF
+ * @return		boolean||null				true if there is an injection. Stop code if injection found.
  */
-function analyse_sql_and_script(&$var, $type)
+function analyseVarsForSqlAndScriptsInjection(&$var, $type)
 {
     if (is_array($var))
     {
         foreach ($var as $key => $value)
         {
-            if (analyse_sql_and_script($value,$type))
+            if (analyseVarsForSqlAndScriptsInjection($value,$type))
             {
                 $var[$key] = $value;
             }
@@ -147,16 +147,16 @@ if ((defined('NOREQUIREDB') || defined('NOREQUIRETRAN')) && ! defined('NOREQUIRE
 if (! empty($_SERVER["PHP_SELF"]))
 {
     $morevaltochecklikepost=array($_SERVER["PHP_SELF"]);
-    analyse_sql_and_script($morevaltochecklikepost,2);
+    analyseVarsForSqlAndScriptsInjection($morevaltochecklikepost,2);
 }
 // Sanity check on GET parameters
 if (! empty($_SERVER["QUERY_STRING"]))
 {
     $morevaltochecklikeget=array($_SERVER["QUERY_STRING"]);
-    analyse_sql_and_script($morevaltochecklikeget,1);
+    analyseVarsForSqlAndScriptsInjection($morevaltochecklikeget,1);
 }
 // Sanity check on POST
-analyse_sql_and_script($_POST,0);
+analyseVarsForSqlAndScriptsInjection($_POST,0);
 
 // This is to make Dolibarr working with Plesk
 if (! empty($_SERVER['DOCUMENT_ROOT'])) set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');