Skip to content

Commit

Permalink
fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
emalherbi committed Apr 2, 2020
1 parent d8f2ff3 commit 1c47b09
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/INI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
56 changes: 35 additions & 21 deletions src/MyMssql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1c47b09

Please sign in to comment.