Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDI-1434 Replaced $php_errormsg with error_get_last() #113

Merged
merged 1 commit into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/adodb5/drivers/adodb-ads.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,14 @@ function ADODB_ads()
// returns true or false
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;

if (!function_exists('ads_connect')) return null;

if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') {
ADOConnection::outp("For Advantage Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");
}
if (isset($php_errormsg)) $php_errormsg = '';
if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword);
else $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword,$this->curmode);
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
if (isset($this->connectStmt)) $this->Execute($this->connectStmt);

return $this->_connectionID != false;
Expand All @@ -94,20 +91,17 @@ function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
// returns true or false
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;

if (!function_exists('ads_connect')) return null;

if (isset($php_errormsg)) $php_errormsg = '';
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';

$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
if ($this->debug && $argDatabasename) {
ADOConnection::outp("For PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
}
// print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
if ($this->curmode === false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword);
else $this->_connectionID = ads_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);

$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
if ($this->_connectionID && $this->autoRollback) @ads_rollback($this->_connectionID);
if (isset($this->connectStmt)) $this->Execute($this->connectStmt);

Expand Down Expand Up @@ -519,8 +513,6 @@ function Prepare($sql)
/* returns queryID or false */
function _query($sql,$inputarr=false)
{
GLOBAL $php_errormsg;
if (isset($php_errormsg)) $php_errormsg = '';
$this->_error = '';

if ($inputarr) {
Expand All @@ -530,7 +522,7 @@ function _query($sql,$inputarr=false)
$stmtid = ads_prepare($this->_connectionID,$sql);

if ($stmtid == false) {
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
return false;
}
}
Expand Down Expand Up @@ -585,15 +577,15 @@ function _query($sql,$inputarr=false)
$this->_errorCode = 0;
}
else
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
}
else
{
if ($this->_haserrorfunctions) {
$this->_errorMsg = ads_errormsg();
$this->_errorCode = ads_error();
} else
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
}

return $stmtid;
Expand All @@ -614,7 +606,7 @@ function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
$sql = "UPDATE $table SET $column=? WHERE $where";
$stmtid = ads_prepare($this->_connectionID,$sql);
if ($stmtid == false){
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
return false;
}
if (! ads_execute($stmtid,array($val),array(SQL_BINARY) )){
Expand Down
17 changes: 4 additions & 13 deletions src/adodb5/drivers/adodb-db2.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ function ADODB_db2()
// returns true or false
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;

if (!function_exists('db2_connect')) {
ADOConnection::outp("Warning: The old ODBC based DB2 driver has been renamed 'odbc_db2'. This ADOdb driver calls PHP's native db2 extension which is not installed.");
return null;
Expand All @@ -80,7 +78,6 @@ function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
} else {
$this->_connectionID = db2_connect($argDSN,$argUsername,$argPassword);
}
if (isset($php_errormsg)) $php_errormsg = '';

// For db2_connect(), there is an optional 4th arg. If present, it must be
// an array of valid options. So far, we don't use them.
Expand All @@ -95,23 +92,19 @@ function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
// returns true or false
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;

if (!function_exists('db2_connect')) return null;

// This needs to be set before the connect().
// Replaces the odbc_binmode() call that was in Execute()
ini_set('ibm_db2.binmode', $this->binmode);

if (isset($php_errormsg)) $php_errormsg = '';
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';

if ($argDatabasename) {
$this->_connectionID = db2_pconnect($argDatabasename,$argUsername,$argPassword);
} else {
$this->_connectionID = db2_pconnect($argDSN,$argUsername,$argPassword);
}
if (isset($php_errormsg)) $php_errormsg = '';

$this->_errorMsg = @db2_conn_errormsg();
if ($this->_connectionID && $this->autoRollback) @db2_rollback($this->_connectionID);
Expand Down Expand Up @@ -605,8 +598,6 @@ function Prepare($sql)
/* returns queryID or false */
function _query($sql,$inputarr=false)
{
GLOBAL $php_errormsg;
if (isset($php_errormsg)) $php_errormsg = '';
$this->_error = '';

if ($inputarr) {
Expand All @@ -616,7 +607,7 @@ function _query($sql,$inputarr=false)
$stmtid = db2_prepare($this->_connectionID,$sql);

if ($stmtid == false) {
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
return false;
}
}
Expand Down Expand Up @@ -654,13 +645,13 @@ function _query($sql,$inputarr=false)
$this->_errorMsg = '';
$this->_errorCode = 0;
} else
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
} else {
if ($this->_haserrorfunctions) {
$this->_errorMsg = db2_stmt_errormsg();
$this->_errorCode = db2_stmt_error();
} else
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';

}
return $stmtid;
Expand Down
21 changes: 7 additions & 14 deletions src/adodb5/drivers/adodb-odbc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ function ADODB_odbc()
// returns true or false
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;

if (!function_exists('odbc_connect')) return null;

if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') {
ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");
}
if (isset($php_errormsg)) $php_errormsg = '';
if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
if (isset($this->connectStmt)) $this->Execute($this->connectStmt);

return $this->_connectionID != false;
Expand All @@ -67,20 +64,18 @@ function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
// returns true or false
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;

if (!function_exists('odbc_connect')) return null;

if (isset($php_errormsg)) $php_errormsg = '';
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
if ($this->debug && $argDatabasename) {
ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
}
// print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';

$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID);
if (isset($this->connectStmt)) $this->Execute($this->connectStmt);

Expand Down Expand Up @@ -491,8 +486,6 @@ function Prepare($sql)
/* returns queryID or false */
function _query($sql,$inputarr=false)
{
GLOBAL $php_errormsg;
if (isset($php_errormsg)) $php_errormsg = '';
$this->_error = '';

if ($inputarr) {
Expand All @@ -502,7 +495,7 @@ function _query($sql,$inputarr=false)
$stmtid = odbc_prepare($this->_connectionID,$sql);

if ($stmtid == false) {
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
return false;
}
}
Expand Down Expand Up @@ -544,13 +537,13 @@ function _query($sql,$inputarr=false)
$this->_errorMsg = '';
$this->_errorCode = 0;
} else
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
} else {
if ($this->_haserrorfunctions) {
$this->_errorMsg = odbc_errormsg();
$this->_errorCode = odbc_error();
} else
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
}
return $stmtid;
}
Expand Down
9 changes: 2 additions & 7 deletions src/adodb5/drivers/adodb-odbc_oracle.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ function MetaColumns($table, $normalize=true)
// returns true or false
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;

$php_errormsg = '';
$this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC );
$this->_errorMsg = $php_errormsg;
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';

$this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
Expand All @@ -92,10 +89,8 @@ function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
// returns true or false
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;
$php_errormsg = '';
$this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC );
$this->_errorMsg = $php_errormsg;
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';

$this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
Expand Down
4 changes: 1 addition & 3 deletions src/adodb5/drivers/adodb-odbtp.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,6 @@ function IfNull( $field, $ifNull )

function _query($sql,$inputarr=false)
{
global $php_errormsg;

$this->_errorMsg = false;
$this->_errorCode = false;

Expand All @@ -615,7 +613,7 @@ function _query($sql,$inputarr=false)
} else {
$stmtid = @odbtp_prepare($sql,$this->_connectionID);
if ($stmtid == false) {
$this->_errorMsg = $php_errormsg;
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : '';
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/adodb5/drivers/adodb-sybase.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function ErrorMsg()
if (function_exists('sybase_get_last_message'))
$this->_errorMsg = sybase_get_last_message();
else
$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : 'SYBASE error messages not supported on this platform';
$this->_errorMsg = error_get_last() !== null ? error_get_last()['message'] : 'SYBASE error messages not supported on this platform';
return $this->_errorMsg;
}

Expand Down