From 1c47b09d4d2316cd0185b4e53335da5b2c5e0649 Mon Sep 17 00:00:00 2001 From: Eduardo Malherbi Date: Thu, 2 Apr 2020 10:02:04 -0300 Subject: [PATCH] fix some warnings --- .php_cs | 4 +++- src/INI.php | 2 +- src/MyMssql.php | 56 ++++++++++++++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/.php_cs b/.php_cs index 77363fd..bea080c 100755 --- a/.php_cs +++ b/.php_cs @@ -31,8 +31,10 @@ return PhpCsFixer\Config::create() 'phpdoc_order' => true, 'semicolon_after_instruction' => true, 'strict_comparison' => false, - 'strict_param' => true, + 'strict_param' => false, 'dir_constant' => false, + 'native_function_invocation' => false, + 'native_constant_invocation' => false, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/src/INI.php b/src/INI.php index f791c3a..d9beda0 100755 --- a/src/INI.php +++ b/src/INI.php @@ -20,7 +20,7 @@ public static function write($filename, $ini) $string .= self::write_get_string($ini[$key], '').self::RETURN_NEWLINE; } - file_put_contents($filename, $string); + @file_put_contents($filename, $string); } public static function write_get_string(&$ini, $prefix) diff --git a/src/MyMssql.php b/src/MyMssql.php index 87cb31d..e86e8ba 100755 --- a/src/MyMssql.php +++ b/src/MyMssql.php @@ -40,12 +40,26 @@ public function __construct($ini = array(), $dl = '', $type = 'UTF-8') $this->type = $type; // Ex.: ISO-8859-1 if (!empty($ini)) { + $ini = $this->validateIni($ini); $this->setIni($ini); } $this->ini = $this->getIni(); + $this->ini = $this->validateIni($this->ini); + $this->connect(); } + public function validateIni($ini) + { + if (array_key_exists('VERBOSE', $ini)) { + if (!isset($ini['VERBOSE'])) { + $ini['VERBOSE'] = false; + } + } + + return $ini; + } + public function getAdapter() { return (function_exists('mssql_connect')) ? 'MSSQL' : 'SQLSRV'; @@ -102,9 +116,9 @@ public function disconnect() { try { if ('SQLSRV' == $this->ini['ADAPTER']) { - sqlsrv_close($this->db); + @sqlsrv_close($this->db); } else { - mssql_close($this->db); + @mssql_close($this->db); } if (true == $this->ini['VERBOSE']) { @@ -148,10 +162,10 @@ public function begin() } if ('SQLSRV' == $this->ini['ADAPTER']) { - return sqlsrv_begin_transaction($this->db); + return @sqlsrv_begin_transaction($this->db); } - return mssql_query('BEGIN TRANSACTION', $this->db); + return @mssql_query('BEGIN TRANSACTION', $this->db); } catch (Exception $e) { $err = $e->getMessage(); $this->logger('MyMssql Begin Transaction '.$this->ini['ADAPTER'], $err); @@ -169,10 +183,10 @@ public function commit() } if ('SQLSRV' == $this->ini['ADAPTER']) { - return sqlsrv_commit($this->db); + return @sqlsrv_commit($this->db); } - return mssql_query('COMMIT TRANSACTION', $this->db); + return @mssql_query('COMMIT TRANSACTION', $this->db); } catch (Exception $e) { $err = $e->getMessage(); $this->logger('MyMssql Commit '.$this->ini['ADAPTER'], $err); @@ -190,10 +204,10 @@ public function rollback() } if ('SQLSRV' == $this->ini['ADAPTER']) { - return sqlsrv_rollback($this->db); + return @sqlsrv_rollback($this->db); } - return mssql_query('IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION', $this->db); + return @mssql_query('IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION', $this->db); } catch (Exception $e) { $err = $e->getMessage(); $this->logger('MyMssql RollBack '.$this->ini['ADAPTER'], $err); @@ -209,9 +223,9 @@ public function fetchOne($sql) $stmt = $this->query($sql); if ('SQLSRV' == $this->ini['ADAPTER']) { - $result = sqlsrv_fetch_array($stmt); + $result = @sqlsrv_fetch_array($stmt); } else { - $result = mssql_fetch_array($stmt); + $result = @mssql_fetch_array($stmt); } $result = $this->getResult($result); @@ -234,9 +248,9 @@ public function fetchRow($sql) $stmt = $this->query($sql); if ('SQLSRV' == $this->ini['ADAPTER']) { - $result = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC); + $result = @sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC); } else { - $result = mssql_fetch_array($stmt, MSSQL_ASSOC); + $result = @mssql_fetch_array($stmt, MSSQL_ASSOC); } $result = $this->getResult($result); @@ -260,12 +274,12 @@ public function fetchAll($sql) $result = array(); if ('SQLSRV' == $this->ini['ADAPTER']) { - while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { + while ($row = @sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $row = $this->getResult($row); $result[] = $row; } } else { - while ($row = mssql_fetch_array($stmt, MSSQL_ASSOC)) { + while ($row = @mssql_fetch_array($stmt, MSSQL_ASSOC)) { $row = $this->getResult($row); $result[] = $row; } @@ -295,9 +309,9 @@ public function query($sql) } if ('SQLSRV' == $this->ini['ADAPTER']) { - $stmt = sqlsrv_query($this->db, $sql, array(), array('Scrollable' => 'static')); + $stmt = @sqlsrv_query($this->db, $sql, array(), array('Scrollable' => 'static')); } else { - $stmt = mssql_query($sql, $this->db); + $stmt = @mssql_query($sql, $this->db); } if (true == $this->ini['VERBOSE']) { @@ -374,7 +388,7 @@ public function execScriptResult($sql, $isObject = false) if ('SQLSRV' == $this->ini['ADAPTER']) { do { - while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { + while ($row = @sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $row = $this->getResult($row); if (true == $isObject) { $row = (object) $row; @@ -383,7 +397,7 @@ public function execScriptResult($sql, $isObject = false) } } while (sqlsrv_next_result($stmt)); } else { - while ($row = mssql_fetch_array($stmt, MSSQL_ASSOC)) { + while ($row = @mssql_fetch_array($stmt, MSSQL_ASSOC)) { $row = $this->getResult($row); if (true == $isObject) { $row = (object) $row; @@ -521,13 +535,13 @@ private function querySx($sxName, $params, $test = false, $function = 'exec') } else { if ('SQLSRV' == $this->ini['ADAPTER']) { do { - while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { + while ($row = @sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $row = $this->getResult($row); $result = $row; } } while (sqlsrv_next_result($stmt)); } else { - while ($row = mssql_fetch_array($stmt, MSSQL_ASSOC)) { + while ($row = @mssql_fetch_array($stmt, MSSQL_ASSOC)) { $row = $this->getResult($row); $result = $row; } @@ -638,7 +652,7 @@ private function logger($str, $err = '') $log .= "[ERROR] > $err \n\n"; } - $file = fopen($this->DL.$this->DS."log-$date.txt", 'a+b'); + $file = fopen($this->DL.$this->DS."log-$date.txt", 'a+'); fwrite($file, $log); fclose($file); }