Passed
Push — master ( 2a5ce0...65bdac )
by Alxarafe
23:02
created
dolibarr/htdocs/core/db/mssql.class.php 1 patch
Spacing   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 use Alxarafe\Helpers\Debug;
32 32
 
33 33
 //require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php';
34
-require_once DOL_BASE_PATH . '/core/db/DoliDB.class.php';
34
+require_once DOL_BASE_PATH.'/core/db/DoliDB.class.php';
35 35
 
36 36
 /**
37 37
  *	Classe de gestion de la database de dolibarr
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
 class DoliDBMssql extends DoliDB
40 40
 {
41 41
 	//! Database type
42
-	public $type='mssql';
42
+	public $type = 'mssql';
43 43
 	//! Database label
44
-	const LABEL='MSSQL';
44
+	const LABEL = 'MSSQL';
45 45
 	//! Charset used to force charset when creating database
46
-	var $forcecharset='latin1';      // Can't be static as it may be forced with a dynamic value
46
+	var $forcecharset = 'latin1'; // Can't be static as it may be forced with a dynamic value
47 47
 	//! Collate used to force collate when creating database
48
-	var $forcecollate='latin1_swedish_ci';      // Can't be static as it may be forced with a dynamic value
48
+	var $forcecollate = 'latin1_swedish_ci'; // Can't be static as it may be forced with a dynamic value
49 49
 	//! Version min database
50
-	const VERSIONMIN='2000';
50
+	const VERSIONMIN = '2000';
51 51
 	/** @var resource Resultset of last query */
52 52
 	private $_results;
53 53
 
@@ -62,30 +62,30 @@  discard block
 block discarded – undo
62 62
 	 *	@param	    string	$name		Nom de la database
63 63
 	 *	@param	    int		$port		Port of database server
64 64
      */
65
-	function __construct($type, $host, $user, $pass, $name='', $port=0)
65
+	function __construct($type, $host, $user, $pass, $name = '', $port = 0)
66 66
 	{
67 67
 		global $langs;
68 68
 
69
-		$this->database_user=$user;
70
-        $this->database_host=$host;
71
-        $this->database_port=$port;
72
-		$this->transaction_opened=0;
69
+		$this->database_user = $user;
70
+        $this->database_host = $host;
71
+        $this->database_port = $port;
72
+		$this->transaction_opened = 0;
73 73
 
74
-		if (! function_exists("mssql_connect"))
74
+		if (!function_exists("mssql_connect"))
75 75
 		{
76 76
 			$this->connected = false;
77 77
 			$this->ok = false;
78
-			$this->error="Mssql PHP functions for using MSSql driver are not available in this version of PHP";
79
-			dol_syslog(get_class($this)."::DoliDBMssql : MSsql PHP functions for using MSsql driver are not available in this version of PHP",LOG_ERR);
78
+			$this->error = "Mssql PHP functions for using MSSql driver are not available in this version of PHP";
79
+			dol_syslog(get_class($this)."::DoliDBMssql : MSsql PHP functions for using MSsql driver are not available in this version of PHP", LOG_ERR);
80 80
 			return $this->ok;
81 81
 		}
82 82
 
83
-		if (! $host)
83
+		if (!$host)
84 84
 		{
85 85
 			$this->connected = false;
86 86
 			$this->ok = false;
87
-			$this->error=$langs->trans("ErrorWrongHostParameter");
88
-			dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect, wrong host parameters",LOG_ERR);
87
+			$this->error = $langs->trans("ErrorWrongHostParameter");
88
+			dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect, wrong host parameters", LOG_ERR);
89 89
 			return $this->ok;
90 90
 		}
91 91
 
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 			// host, login ou password incorrect
104 104
 			$this->connected = false;
105 105
 			$this->ok = false;
106
-			$this->error=mssql_get_last_message();
107
-			dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect mssql_get_last_message=".$this->error,LOG_ERR);
106
+			$this->error = mssql_get_last_message();
107
+			dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect mssql_get_last_message=".$this->error, LOG_ERR);
108 108
 		}
109 109
 
110 110
 		// Si connexion serveur ok et si connexion base demandee, on essaie connexion base
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
 				$this->database_selected = false;
122 122
 				$this->database_name = '';
123 123
 				$this->ok = false;
124
-				$this->error=$this->error();
125
-				dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error,LOG_ERR);
124
+				$this->error = $this->error();
125
+				dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error, LOG_ERR);
126 126
 			}
127 127
 		}
128 128
 		else
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      *  @param     string	$type	Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
142 142
      *  @return    string   		SQL request line converted
143 143
      */
144
-	static function convertSQLFromMysql($line,$type='ddl')
144
+	static function convertSQLFromMysql($line, $type = 'ddl')
145 145
 	{
146 146
 		return $line;
147 147
 	}
@@ -170,25 +170,25 @@  discard block
 block discarded – undo
170 170
 	 *	@return		false|resource|true	Database access handler
171 171
 	 *	@see		close
172 172
 	 */
173
-	function connect($host, $login, $passwd, $name, $port=0)
173
+	function connect($host, $login, $passwd, $name, $port = 0)
174 174
 	{
175 175
 		dol_syslog(get_class($this)."::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name");
176
-		$newhost=$host;
177
-		if ($port) $newhost.=':'.$port;
178
-		$this->db  = @mssql_connect($newhost, $login, $passwd);
176
+		$newhost = $host;
177
+		if ($port) $newhost .= ':'.$port;
178
+		$this->db = @mssql_connect($newhost, $login, $passwd);
179 179
 		//force les enregistrement en latin1 si la base est en utf8 par defaut
180 180
 		// Supprime car plante sur mon PHP-Mysql. De plus, la base est forcement en latin1 avec
181 181
 		// les nouvelles version de Dolibarr car force par l'install Dolibarr.
182 182
 		//$this->query('SET NAMES '.$this->forcecharset);
183 183
 		//print "Resultat fonction connect: ".$this->db;
184
-		$set_options=array('SET ANSI_PADDING ON;',
184
+		$set_options = array('SET ANSI_PADDING ON;',
185 185
 		    "SET ANSI_NULLS ON;",
186 186
 		    "SET ANSI_WARNINGS ON;",
187 187
 		    "SET ARITHABORT ON;",
188 188
 		    "SET CONCAT_NULL_YIELDS_NULL ON;",
189 189
 		    "SET QUOTED_IDENTIFIER ON;"
190 190
 		);
191
-		mssql_query(implode(' ',$set_options),$this->db);
191
+		mssql_query(implode(' ', $set_options), $this->db);
192 192
 
193 193
 		return $this->db;
194 194
 	}
@@ -200,10 +200,10 @@  discard block
 block discarded – undo
200 200
 	 */
201 201
 	function getVersion()
202 202
 	{
203
-		$resql=$this->query("SELECT @@VERSION");
203
+		$resql = $this->query("SELECT @@VERSION");
204 204
 		if ($resql)
205 205
 		{
206
-            $version=$this->fetch_array($resql);
206
+            $version = $this->fetch_array($resql);
207 207
             return $version['computed'];
208 208
 		}
209 209
 		else return '';
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
     {
230 230
         if ($this->db)
231 231
         {
232
-          if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
233
-          $this->connected=false;
232
+          if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR);
233
+          $this->connected = false;
234 234
           return mssql_close($this->db);
235 235
         }
236 236
         return false;
@@ -245,16 +245,16 @@  discard block
 block discarded – undo
245 245
 	function begin()
246 246
 	{
247 247
 
248
-	    $res=mssql_query('select @@TRANCOUNT');
249
-	    $this->transaction_opened=mssql_result($res, 0, 0);
248
+	    $res = mssql_query('select @@TRANCOUNT');
249
+	    $this->transaction_opened = mssql_result($res, 0, 0);
250 250
 
251 251
 	    if ($this->transaction_opened == 0)
252 252
 		{
253 253
 		    //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTIONS ON' generate also a mess
254
-			$ret=mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;",$this->db);
254
+			$ret = mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;", $this->db);
255 255
 			if ($ret)
256 256
 			{
257
-				dol_syslog("BEGIN Transaction",LOG_DEBUG);
257
+				dol_syslog("BEGIN Transaction", LOG_DEBUG);
258 258
 			}
259 259
 			return $ret;
260 260
 		}
@@ -270,18 +270,18 @@  discard block
 block discarded – undo
270 270
      * @param	string	$log        Add more log to default log line
271 271
      * @return  bool         		true if validation is OK or transaction level no started, false if ERROR
272 272
 	 */
273
-	function commit($log='')
273
+	function commit($log = '')
274 274
 	{
275
-	    $res=mssql_query('select @@TRANCOUNT');
276
-	    $this->transaction_opened=mssql_result($res, 0, 0);
275
+	    $res = mssql_query('select @@TRANCOUNT');
276
+	    $this->transaction_opened = mssql_result($res, 0, 0);
277 277
 
278 278
 		if ($this->transaction_opened == 1)
279 279
 		{
280 280
 		    //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTION ON' generate also a mess
281
-			$ret=mssql_query("COMMIT TRANSACTION",$this->db);
281
+			$ret = mssql_query("COMMIT TRANSACTION", $this->db);
282 282
 			if ($ret)
283 283
 			{
284
-				dol_syslog("COMMIT Transaction",LOG_DEBUG);
284
+				dol_syslog("COMMIT Transaction", LOG_DEBUG);
285 285
 				return true;
286 286
 			}
287 287
 			else
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 	 * @param	string	$log	Add more log to default log line
304 304
 	 * @return	bool             true si annulation ok ou transaction non ouverte, false en cas d'erreur
305 305
 	 */
306
-	function rollback($log='')
306
+	function rollback($log = '')
307 307
 	{
308
-	    $res=mssql_query('select @@TRANCOUNT');
309
-	    $this->transaction_opened=mssql_result($res, 0, 0);
308
+	    $res = mssql_query('select @@TRANCOUNT');
309
+	    $this->transaction_opened = mssql_result($res, 0, 0);
310 310
 
311 311
 		if ($this->transaction_opened == 1)
312 312
 		{
313
-			$ret=mssql_query("ROLLBACK TRANSACTION",$this->db);
314
-			dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG);
313
+			$ret = mssql_query("ROLLBACK TRANSACTION", $this->db);
314
+			dol_syslog("ROLLBACK Transaction".($log ? ' '.$log : ''), LOG_DEBUG);
315 315
 			return $ret;
316 316
 		}
317 317
 		elseif ($this->transaction_opened > 1)
@@ -331,61 +331,61 @@  discard block
 block discarded – undo
331 331
      *  @param  string	$type           Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
332 332
      *  @return false|resource|true		Resultset of answer
333 333
 	 */
334
-	function query($query,$usesavepoint=0,$type='auto')
334
+	function query($query, $usesavepoint = 0, $type = 'auto')
335 335
 	{
336 336
 		$query = trim($query);
337 337
 
338
-        Debug::addMessage('SQL', 'MSSQL: ' . $query);
338
+        Debug::addMessage('SQL', 'MSSQL: '.$query);
339 339
 
340
-        if (preg_match('/^--/',$query)) return true;
340
+        if (preg_match('/^--/', $query)) return true;
341 341
 
342 342
 		// Conversion syntaxe MySql vers MSDE.
343 343
 		$query = str_ireplace("now()", "getdate()", $query);
344 344
 		// Erreur SQL: cannot update timestamp field
345 345
 		$query = str_ireplace(", tms = tms", "", $query);
346 346
 
347
-		$query=preg_replace("/([. ,\t(])(percent|file|public)([. ,=\t)])/","$1[$2]$3",$query);
347
+		$query = preg_replace("/([. ,\t(])(percent|file|public)([. ,=\t)])/", "$1[$2]$3", $query);
348 348
 
349
-		if ($type=="auto" || $type='dml')
349
+		if ($type == "auto" || $type = 'dml')
350 350
 		{
351
-    		$query=preg_replace('/AUTO_INCREMENT/i','IDENTITY',$query);
352
-    		$query=preg_replace('/double/i','float',$query);
353
-    		$query=preg_replace('/float\((.*)\)/','numeric($1)',$query);
354
-    		$query=preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i','$1',$query);
355
-    		$query=preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i',"$1VARCHAR(MAX)$3",$query);
356
-
357
-    		$matches=array();
358
-    		$original_query='';
359
-    		if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query,$matches))
351
+    		$query = preg_replace('/AUTO_INCREMENT/i', 'IDENTITY', $query);
352
+    		$query = preg_replace('/double/i', 'float', $query);
353
+    		$query = preg_replace('/float\((.*)\)/', 'numeric($1)', $query);
354
+    		$query = preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i', '$1', $query);
355
+    		$query = preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i', "$1VARCHAR(MAX)$3", $query);
356
+
357
+    		$matches = array();
358
+    		$original_query = '';
359
+    		if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query, $matches))
360 360
     		{
361
-                $original_query=$query;
362
-                $query="CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")";
361
+                $original_query = $query;
362
+                $query = "CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")";
363 363
                 if ($matches[2]) {
364 364
                     //check if columun is nullable cause Sql server only allow 1 null value if unique index.
365
-                    $fields=explode(",",trim($matches[4]));
366
-                    $fields_clear=array_map('trim',$fields);
367
-                    $infos=$this->GetFieldInformation(trim($matches[1]), $fields_clear);
368
-                    $query_comp=array();
369
-                    foreach($infos as $fld) {
365
+                    $fields = explode(",", trim($matches[4]));
366
+                    $fields_clear = array_map('trim', $fields);
367
+                    $infos = $this->GetFieldInformation(trim($matches[1]), $fields_clear);
368
+                    $query_comp = array();
369
+                    foreach ($infos as $fld) {
370 370
                         if ($fld->IS_NULLABLE == 'YES') {
371
-                            $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL";
371
+                            $query_comp[] = $fld->COLUMN_NAME." IS NOT NULL";
372 372
                         }
373 373
                     }
374
-                    if (! empty($query_comp))
375
-                        $query.=" WHERE ".implode(" AND ",$query_comp);
374
+                    if (!empty($query_comp))
375
+                        $query .= " WHERE ".implode(" AND ", $query_comp);
376 376
                 }
377 377
     		}
378 378
     		else
379 379
     		{
380 380
     		    if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches))
381 381
     		    {
382
-                    $original_query=$query;
383
-                    $query="ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")";
382
+                    $original_query = $query;
383
+                    $query = "ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")";
384 384
     		    }
385 385
     		}
386 386
 		}
387 387
 
388
-		if ($type=="auto" || $type='ddl')
388
+		if ($type == "auto" || $type = 'ddl')
389 389
 		{
390 390
     		$itemfound = stripos($query, " limit ");
391 391
     		if ($itemfound !== false) {
@@ -416,21 +416,21 @@  discard block
 block discarded – undo
416 416
     			// Inserer la date en parametre et le reste de la requete
417 417
     			$query = $newquery." DATEPART(week, ".$extractvalue.$endofquery;
418 418
     		}
419
-    	   if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i',$query,$matches))
419
+    	   if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i', $query, $matches))
420 420
     	   {
421 421
     	       //var_dump($query);
422 422
     	       //var_dump($matches);
423 423
     	       //if (stripos($query,'llx_c_departements') !== false) var_dump($query);
424
-    	       $sql='SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;';
424
+    	       $sql = 'SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;';
425 425
     	       @mssql_query($sql, $this->db);
426
-    	       $post_query='SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;';
426
+    	       $post_query = 'SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;';
427 427
     	   }
428 428
 		}
429 429
 		//print "<!--".$query."-->";
430 430
 
431
-		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
431
+		if (!in_array($query, array('BEGIN', 'COMMIT', 'ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
432 432
 
433
-		if (! $this->database_name)
433
+		if (!$this->database_name)
434 434
 		{
435 435
 			// Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE)
436 436
 			$ret = mssql_query($query, $this->db);
@@ -445,10 +445,10 @@  discard block
 block discarded – undo
445 445
 		    @mssql_query($post_query, $this->db);
446 446
 		}
447 447
 
448
-		if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query))
448
+		if (!preg_match("/^COMMIT/i", $query) && !preg_match("/^ROLLBACK/i", $query))
449 449
 		{
450 450
 			// Si requete utilisateur, on la sauvegarde ainsi que son resultset
451
-			if (! $ret)
451
+			if (!$ret)
452 452
 			{
453 453
 				$result = mssql_query("SELECT @@ERROR as code", $this->db);
454 454
 				$row = mssql_fetch_array($result);
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 				if ($original_query) dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR);
462 462
 				dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR);
463 463
 			}
464
-			$this->lastquery=$query;
464
+			$this->lastquery = $query;
465 465
 			$this->_results = $ret;
466 466
 		}
467 467
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 	{
480 480
         // phpcs:enable
481 481
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
482
-		if (! is_resource($resultset)) { $resultset=$this->_results; }
482
+		if (!is_resource($resultset)) { $resultset = $this->_results; }
483 483
 		return mssql_fetch_object($resultset);
484 484
 	}
485 485
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 	{
495 495
         // phpcs:enable
496 496
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
497
-		if (! is_resource($resultset)) { $resultset=$this->_results; }
497
+		if (!is_resource($resultset)) { $resultset = $this->_results; }
498 498
 		return mssql_fetch_array($resultset);
499 499
 	}
500 500
 
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	{
511 511
         // phpcs:enable
512 512
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
513
-		if (! is_resource($resultset)) { $resultset=$this->_results; }
513
+		if (!is_resource($resultset)) { $resultset = $this->_results; }
514 514
 		return @mssql_fetch_row($resultset);
515 515
 	}
516 516
 
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 	{
527 527
         // phpcs:enable
528 528
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
529
-		if (! is_resource($resultset)) { $resultset=$this->_results; }
529
+		if (!is_resource($resultset)) { $resultset = $this->_results; }
530 530
 		return mssql_num_rows($resultset);
531 531
 	}
532 532
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 	{
543 543
         // phpcs:enable
544 544
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
545
-		if (! is_resource($resultset)) { $resultset=$this->_results; }
545
+		if (!is_resource($resultset)) { $resultset = $this->_results; }
546 546
 		// mssql necessite un link de base pour cette fonction contrairement
547 547
 		// a pqsql qui prend un resultset
548 548
 		$rsRows = mssql_query("select @@rowcount as rows", $this->db);
@@ -557,10 +557,10 @@  discard block
 block discarded – undo
557 557
 	 *	@param  resource	$resultset   Curseur de la requete voulue
558 558
 	 *	@return	bool
559 559
 	 */
560
-	function free($resultset=null)
560
+	function free($resultset = null)
561 561
 	{
562 562
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
563
-		if (! is_resource($resultset)) { $resultset=$this->_results; }
563
+		if (!is_resource($resultset)) { $resultset = $this->_results; }
564 564
 		// Si resultset en est un, on libere la memoire
565 565
 		if (is_resource($resultset)) mssql_free_result($resultset);
566 566
 	}
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 	 */
587 587
 	function idate($param)
588 588
 	{
589
-		return dol_print_date($param,"%Y-%m-%d %H:%M:%S");
589
+		return dol_print_date($param, "%Y-%m-%d %H:%M:%S");
590 590
 	}
591 591
 
592 592
 	/**
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 	 */
597 597
 	function errno()
598 598
 	{
599
-		if (! $this->connected)
599
+		if (!$this->connected)
600 600
 		{
601 601
 			// Si il y a eu echec de connexion, $this->db n'est pas valide.
602 602
 			return 'DB_ERROR_FAILED_TO_CONNECT';
@@ -637,8 +637,8 @@  discard block
 block discarded – undo
637 637
 			{
638 638
 				return $errorcode_map[$this->lasterrno];
639 639
 			}
640
-			$errno=$this->lasterrno;
641
-			return ($errno?'DB_ERROR_'.$errno:'0');
640
+			$errno = $this->lasterrno;
641
+			return ($errno ? 'DB_ERROR_'.$errno : '0');
642 642
 		}
643 643
 	}
644 644
 
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 	 */
650 650
 	function error()
651 651
 	{
652
-		if (! $this->connected) {
652
+		if (!$this->connected) {
653 653
 			// Si il y a eu echec de connexion, $this->db n'est pas valide pour mssql_get_last_message.
654 654
 			return 'Not connected. Check setup parameters in conf/conf.php file and your mssql client and server versions';
655 655
 		}
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 	 * @param	string	$fieldid	Field name
667 667
 	 * @return  int     			Id of row or -1 on error
668 668
 	 */
669
-	function last_insert_id($tab,$fieldid='rowid')
669
+	function last_insert_id($tab, $fieldid = 'rowid')
670 670
 	{
671 671
         // phpcs:enable
672 672
 		$res = $this->query("SELECT @@IDENTITY as id");
@@ -688,18 +688,18 @@  discard block
 block discarded – undo
688 688
      *  @param	int		$withQuotes     Return string with quotes
689 689
      *  @return string          		XXX(field) or XXX('value') or field or 'value'
690 690
 	 */
691
-	function encrypt($fieldorvalue, $withQuotes=0)
691
+	function encrypt($fieldorvalue, $withQuotes = 0)
692 692
 	{
693 693
 		global $conf;
694 694
 
695 695
 		// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
696
-		$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
696
+		$cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0);
697 697
 
698 698
 		//Encryption key
699
-		$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
699
+		$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : '');
700 700
 
701 701
 		$return = $fieldorvalue;
702
-		return ($withQuotes?"'":"").$this->escape($return).($withQuotes?"'":"");
702
+		return ($withQuotes ? "'" : "").$this->escape($return).($withQuotes ? "'" : "");
703 703
 	}
704 704
 
705 705
 	/**
@@ -713,10 +713,10 @@  discard block
 block discarded – undo
713 713
 		global $conf;
714 714
 
715 715
 		// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
716
-		$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
716
+		$cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0);
717 717
 
718 718
 		//Encryption key
719
-		$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
719
+		$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : '');
720 720
 
721 721
 		$return = $value;
722 722
 		return $return;
@@ -732,10 +732,10 @@  discard block
 block discarded – undo
732 732
 	function DDLGetConnectId()
733 733
 	{
734 734
         // phpcs:enable
735
-		$resql=$this->query('SELECT CONNECTION_ID()');
735
+		$resql = $this->query('SELECT CONNECTION_ID()');
736 736
 		if ($resql)
737 737
 		{
738
-            $row=$this->fetch_row($resql);
738
+            $row = $this->fetch_row($resql);
739 739
             return $row[0];
740 740
 		}
741 741
 		else return '?';
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
 	 * 	@param	string	$owner			Username of database owner
754 754
 	 * 	@return	false|resource|true		resource defined if OK, false if KO
755 755
 	 */
756
-	function DDLCreateDb($database,$charset='',$collation='',$owner='')
756
+	function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
757 757
 	{
758 758
         // phpcs:enable
759 759
         /*if (empty($charset))   $charset=$this->forcecharset;
@@ -763,18 +763,18 @@  discard block
 block discarded – undo
763 763
 		$sql = 'CREATE DATABASE '.$this->EscapeFieldName($database);
764 764
         //TODO: Check if we need to force a charset
765 765
 		//$sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation;
766
-		$ret=$this->query($sql);
766
+		$ret = $this->query($sql);
767 767
 
768 768
 		$this->select_db($database);
769
-		$sql="CREATE USER [$owner] FOR LOGIN [$owner]";
770
-		mssql_query($sql,$this->db);
771
-		$sql="ALTER ROLE [db_owner] ADD MEMBER [$owner]";
772
-		mssql_query($sql,$this->db);
769
+		$sql = "CREATE USER [$owner] FOR LOGIN [$owner]";
770
+		mssql_query($sql, $this->db);
771
+		$sql = "ALTER ROLE [db_owner] ADD MEMBER [$owner]";
772
+		mssql_query($sql, $this->db);
773 773
 
774
-		$sql="ALTER DATABASE [$database] SET ANSI_NULL_DEFAULT ON;";
775
-	    @mssql_query($sql,$this->db);
776
-	    $sql="ALTER DATABASE [$database] SET ANSI_NULL ON;";
777
-	    @mssql_query($sql,$this->db);
774
+		$sql = "ALTER DATABASE [$database] SET ANSI_NULL_DEFAULT ON;";
775
+	    @mssql_query($sql, $this->db);
776
+	    $sql = "ALTER DATABASE [$database] SET ANSI_NULL ON;";
777
+	    @mssql_query($sql, $this->db);
778 778
 
779 779
 	    return $ret;
780 780
 	}
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 	 *  @param	string		$table		Nmae of table filter ('xxx%')
788 788
      *  @return	array					List of tables in an array
789 789
 	 */
790
-	function DDLListTables($database,$table='')
790
+	function DDLListTables($database, $table = '')
791 791
 	{
792 792
         // phpcs:enable
793 793
 		$this->_results = mssql_list_tables($database, $this->db);
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
 		// TODO: Implement
810 810
 		// May help: https://stackoverflow.com/questions/600446/sql-server-how-do-you-return-the-column-names-from-a-table
811 811
 
812
-		$infotables=array();
812
+		$infotables = array();
813 813
 		return $infotables;
814 814
 	}
815 815
 
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 	 *	@param	    array	$keys 			Tableau des champs cles noms => valeur
827 827
 	 *	@return	    int						<0 if KO, >=0 if OK
828 828
 	 */
829
-	function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null)
829
+	function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null)
830 830
 	{
831 831
         // phpcs:enable
832 832
 		// FIXME: $fulltext_keys parameter is unused
@@ -834,58 +834,58 @@  discard block
 block discarded – undo
834 834
 		// cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra
835 835
 		// ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
836 836
 		$sql = "create table ".$table."(";
837
-		$i=0;
838
-		foreach($fields as $field_name => $field_desc)
837
+		$i = 0;
838
+		foreach ($fields as $field_name => $field_desc)
839 839
 		{
840 840
 			$sqlfields[$i] = $field_name." ";
841 841
 			$sqlfields[$i]  .= $field_desc['type'];
842
-			if( preg_match("/^[^\s]/i",$field_desc['value']))
842
+			if (preg_match("/^[^\s]/i", $field_desc['value']))
843 843
 			$sqlfields[$i]  .= "(".$field_desc['value'].")";
844
-			else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
844
+			else if (preg_match("/^[^\s]/i", $field_desc['attribute']))
845 845
 			$sqlfields[$i]  .= " ".$field_desc['attribute'];
846
-			else if( preg_match("/^[^\s]/i",$field_desc['default']))
846
+			else if (preg_match("/^[^\s]/i", $field_desc['default']))
847 847
 			{
848
-				if(preg_match("/null/i",$field_desc['default']))
848
+				if (preg_match("/null/i", $field_desc['default']))
849 849
 				$sqlfields[$i]  .= " default ".$field_desc['default'];
850 850
 				else
851 851
 				$sqlfields[$i]  .= " default '".$field_desc['default']."'";
852 852
 			}
853
-			else if( preg_match("/^[^\s]/i",$field_desc['null']))
853
+			else if (preg_match("/^[^\s]/i", $field_desc['null']))
854 854
 			$sqlfields[$i]  .= " ".$field_desc['null'];
855 855
 
856
-			else if( preg_match("/^[^\s]/i",$field_desc['extra']))
856
+			else if (preg_match("/^[^\s]/i", $field_desc['extra']))
857 857
 			$sqlfields[$i]  .= " ".$field_desc['extra'];
858 858
 			$i++;
859 859
 		}
860
-		if($primary_key != "")
860
+		if ($primary_key != "")
861 861
 		$pk = "primary key(".$primary_key.")";
862 862
 
863
-		if(is_array($unique_keys))
863
+		if (is_array($unique_keys))
864 864
 		{
865 865
 			$i = 0;
866
-			foreach($unique_keys as $key => $value)
866
+			foreach ($unique_keys as $key => $value)
867 867
 			{
868 868
 				$sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')";
869 869
 				$i++;
870 870
 			}
871 871
 		}
872
-		if(is_array($keys))
872
+		if (is_array($keys))
873 873
 		{
874 874
 			$i = 0;
875
-			foreach($keys as $key => $value)
875
+			foreach ($keys as $key => $value)
876 876
 			{
877 877
 				$sqlk[$i] = "KEY ".$key." (".$value.")";
878 878
 				$i++;
879 879
 			}
880 880
 		}
881
-		$sql .= implode(',',$sqlfields);
882
-		if($primary_key != "")
881
+		$sql .= implode(',', $sqlfields);
882
+		if ($primary_key != "")
883 883
 		$sql .= ",".$pk;
884
-		if(is_array($unique_keys))
885
-		$sql .= ",".implode(',',$sqluq);
886
-		if(is_array($keys))
887
-		$sql .= ",".implode(',',$sqlk);
888
-		$sql .=") type=".$type;
884
+		if (is_array($unique_keys))
885
+		$sql .= ",".implode(',', $sqluq);
886
+		if (is_array($keys))
887
+		$sql .= ",".implode(',', $sqlk);
888
+		$sql .= ") type=".$type;
889 889
 
890 890
 		dol_syslog($sql);
891 891
 		if (!$this->query($sql))
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
         // phpcs:enable
907 907
 		$sql = "DROP TABLE ".$table;
908 908
 
909
-		if (! $this->query($sql))
909
+		if (!$this->query($sql))
910 910
 			return -1;
911 911
 		else
912 912
 			return 1;
@@ -920,10 +920,10 @@  discard block
 block discarded – undo
920 920
 	 *	@param	string		$field	Optionnel : Name of field if we want description of field
921 921
 	 *	@return	false|resource|true	Resource
922 922
 	 */
923
-	function DDLDescTable($table,$field="")
923
+	function DDLDescTable($table, $field = "")
924 924
 	{
925 925
         // phpcs:enable
926
-		$sql="DESC ".$table." ".$field;
926
+		$sql = "DESC ".$table." ".$field;
927 927
 
928 928
 		dol_syslog($sql);
929 929
 		$this->_results = $this->query($sql);
@@ -940,25 +940,25 @@  discard block
 block discarded – undo
940 940
 	 *	@param	string	$field_position 	Optionnel ex.: "after champtruc"
941 941
 	 *	@return	int							<0 if KO, >0 if OK
942 942
 	 */
943
-	function DDLAddField($table,$field_name,$field_desc,$field_position="")
943
+	function DDLAddField($table, $field_name, $field_desc, $field_position = "")
944 944
 	{
945 945
         // phpcs:enable
946 946
 		// cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra
947 947
 		// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
948
-		$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
948
+		$sql = "ALTER TABLE ".$table." ADD ".$field_name." ";
949 949
 		$sql .= $field_desc['type'];
950
-		if( preg_match("/^[^\s]/i",$field_desc['value']))
950
+		if (preg_match("/^[^\s]/i", $field_desc['value']))
951 951
 		$sql  .= "(".$field_desc['value'].")";
952
-		if( preg_match("/^[^\s]/i",$field_desc['attribute']))
952
+		if (preg_match("/^[^\s]/i", $field_desc['attribute']))
953 953
 		$sql  .= " ".$field_desc['attribute'];
954
-		if( preg_match("/^[^\s]/i",$field_desc['null']))
954
+		if (preg_match("/^[^\s]/i", $field_desc['null']))
955 955
 		$sql  .= " ".$field_desc['null'];
956
-		if( preg_match("/^[^\s]/i",$field_desc['default']))
957
-		if(preg_match("/null/i",$field_desc['default']))
956
+		if (preg_match("/^[^\s]/i", $field_desc['default']))
957
+		if (preg_match("/null/i", $field_desc['default']))
958 958
 		$sql  .= " default ".$field_desc['default'];
959 959
 		else
960 960
 		$sql  .= " default '".$field_desc['default']."'";
961
-		if( preg_match("/^[^\s]/i",$field_desc['extra']))
961
+		if (preg_match("/^[^\s]/i", $field_desc['extra']))
962 962
 		$sql  .= " ".$field_desc['extra'];
963 963
 		$sql .= " ".$field_position;
964 964
 
@@ -977,17 +977,17 @@  discard block
 block discarded – undo
977 977
 	 *	@param	string	$field_desc 		Array with description of field format
978 978
 	 *	@return	int							<0 if KO, >0 if OK
979 979
 	 */
980
-	function DDLUpdateField($table,$field_name,$field_desc)
980
+	function DDLUpdateField($table, $field_name, $field_desc)
981 981
 	{
982 982
         // phpcs:enable
983 983
 		$sql = "ALTER TABLE ".$table;
984 984
 		$sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type'];
985 985
 		if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') {
986
-			$sql.="(".$field_desc['value'].")";
986
+			$sql .= "(".$field_desc['value'].")";
987 987
 		}
988 988
 
989
-		dol_syslog($sql,LOG_DEBUG);
990
-		if (! $this->query($sql))
989
+		dol_syslog($sql, LOG_DEBUG);
990
+		if (!$this->query($sql))
991 991
 		return -1;
992 992
 		else
993 993
 		return 1;
@@ -1001,14 +1001,14 @@  discard block
 block discarded – undo
1001 1001
 	 *	@param	string	$field_name 	Name of field to drop
1002 1002
 	 *	@return	int						<0 if KO, >0 if OK
1003 1003
 	 */
1004
-	function DDLDropField($table,$field_name)
1004
+	function DDLDropField($table, $field_name)
1005 1005
 	{
1006 1006
         // phpcs:enable
1007
-		$sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`";
1008
-		dol_syslog($sql,LOG_DEBUG);
1009
-		if (! $this->query($sql))
1007
+		$sql = "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`";
1008
+		dol_syslog($sql, LOG_DEBUG);
1009
+		if (!$this->query($sql))
1010 1010
 		{
1011
-			$this->error=$this->lasterror();
1011
+			$this->error = $this->lasterror();
1012 1012
 			return -1;
1013 1013
 		}
1014 1014
 		else return 1;
@@ -1024,13 +1024,13 @@  discard block
 block discarded – undo
1024 1024
 	 *	@param	string	$dolibarr_main_db_name		Database name where user must be granted
1025 1025
 	 *	@return	int									<0 if KO, >=0 if OK
1026 1026
 	 */
1027
-	function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name)
1027
+	function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name)
1028 1028
 	{
1029 1029
         // phpcs:enable
1030 1030
         $sql = "CREATE LOGIN ".$this->EscapeFieldName($dolibarr_main_db_user)." WITH PASSWORD='$dolibarr_main_db_pass'";
1031
-        dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG);	// No sql to avoid password in log
1032
-        $resql=$this->query($sql);
1033
-        if (! $resql)
1031
+        dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log
1032
+        $resql = $this->query($sql);
1033
+        if (!$resql)
1034 1034
         {
1035 1035
             if ($this->lasterrno != '15025')
1036 1036
             {
@@ -1042,9 +1042,9 @@  discard block
 block discarded – undo
1042 1042
             	dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
1043 1043
             }
1044 1044
         }
1045
-        $sql="SELECT name from sys.databases where name='".$dolibarr_main_db_name."'";
1046
-        $ressql=$this->query($sql);
1047
-        if (! $ressql)
1045
+        $sql = "SELECT name from sys.databases where name='".$dolibarr_main_db_name."'";
1046
+        $ressql = $this->query($sql);
1047
+        if (!$ressql)
1048 1048
         {
1049 1049
             dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
1050 1050
             return -1;
@@ -1054,9 +1054,9 @@  discard block
 block discarded – undo
1054 1054
             if ($num)
1055 1055
             {
1056 1056
                 $this->select_db($dolibarr_main_db_name);
1057
-                $sql="CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]";
1057
+                $sql = "CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]";
1058 1058
                 $this->query($sql);
1059
-                $sql="ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]";
1059
+                $sql = "ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]";
1060 1060
                 $this->query($sql);
1061 1061
             }
1062 1062
         }
@@ -1096,12 +1096,12 @@  discard block
 block discarded – undo
1096 1096
 	 */
1097 1097
 	function getDefaultCollationDatabase()
1098 1098
 	{
1099
-		$resql=$this->query("SELECT SERVERPROPERTY('collation')");
1099
+		$resql = $this->query("SELECT SERVERPROPERTY('collation')");
1100 1100
 		if (!$resql)
1101 1101
 		{
1102 1102
 			return $this->forcecollate;
1103 1103
 		}
1104
-		$liste=$this->fetch_array($resql);
1104
+		$liste = $this->fetch_array($resql);
1105 1105
 		return $liste['computed'];
1106 1106
 	}
1107 1107
 
@@ -1150,13 +1150,13 @@  discard block
 block discarded – undo
1150 1150
 	 * @param	string	$filter		Filter list on a particular value
1151 1151
 	 * @return	array				Array of key-values (key=>value)
1152 1152
 	 */
1153
-	function getServerParametersValues($filter='')
1153
+	function getServerParametersValues($filter = '')
1154 1154
 	{
1155 1155
 		// FIXME: Dummy method
1156 1156
 		// TODO: Implement
1157 1157
 		// May help: SELECT SERVERPROPERTY
1158 1158
 
1159
-		$result=array();
1159
+		$result = array();
1160 1160
 		return $result;
1161 1161
 	}
1162 1162